9

をモンゴする投稿はありません。私は[email protected]を使ってアプリケーションを作っています。私は '/imports/api/collections/recipe.js'という名前のファイルを作っています。ここではコレクションを作成し、このファイルを '/server/main.js'と '/client/main.js'の両方にインポートします。 recipe.jsだけで、私はレシピコレクションを公開していて、クライアントのファイルに登録しています。この点まではすべて正しいです。それから、私はautoformを使ってフォームを作成します。これはうまく動作し、作成されます。しかし、このフォームは決して投稿されません。流星のコレクションは、私は流星とモンゴDBに新しいですデシベル

まず第一に、私の仮定は、サーバーの起動時に、その時点で私のDBはレシピという名前のコレクションを作成している必要があることだったが、それはしていません。

次に、なぜautoformが機能しないのですか?私は最初の理由のためにそれを考える。クライアント側では

、私は(流星-おもちゃの)モンゴルを通じて私のレシピのコレクションを見ることが。

'/imports/api/collections/recipe.js' [ファイル] - [マイレシピ:

import { Meteor } from 'meteor/meteor'; 
import { Mongo } from 'meteor/mongo'; 
import { SimpleSchema } from 'meteor/aldeed:simple-schema'; 

var RecipesCollection = new Mongo.Collection('recipes'); 

RecipesCollection.allow({ 
    insert(userId, doc){ 
     return !!userId; 
    } 
}) 

var RecipeSchema = new SimpleSchema({ 
    name: { 
     type: String, 
     label: "Name" 
    }, 
    desc: { 
     type: String, 
     label: "Description" 
    }, 
    author: { 
     type: String, 
     label: "Author", 
     autoValue(){ 
      return this.userId 
     }, 
     autoform:{ 
      type: "hidden" 
     } 
    }, 
    createdAt: { 
     type: Date, 
     label: "Created At", 
     autoValue(){ 
      return new Date(); 
     }, 
     autoform:{ 
      type: "hidden" 
     } 
    } 
}); 

RecipesCollection.attachSchema(RecipeSchema); 

if (Meteor.isServer) { 
    // This code only runs on the server 
    Meteor.publish('recipes', function tasksPublication() { 
    return RecipesCollection.find({author: this.userId}); 
    }); 
} 

export const Recipes = RecipesCollection; 

私のサーバのファイル: '/server/main.js':

import { Meteor } from 'meteor/meteor'; 
import '/imports/startup/server/start.js'; 
import '/imports/api/collections/recipe.js'; 

私のクライアントのJSファイル:

import { Template } from 'meteor/templating'; 
import { Recipes } from '/imports/api/collections/recipe.js'; 

import '/imports/ui/pages/NewRecipe.html'; 
Template.NewRecipe.onCreated(function bodyOnCreated() { 
    Meteor.subscribe('recipes'); 
}) 
Template.NewRecipe.helpers({ 
    recipesCollection() { 
     return Recipes; 
    } 
}); 

新しいレシピテンプレート:

<template name="NewRecipe"> 
    <div class="new-recipe-container"> 
     {{> quickForm collection=recipesCollection id="insertRecipeForm" type="insert" class="new-recipe-form" }} 
    </div> 
</template> 

私はパッケージCollection2と自動フォームを使用しています。助けや助言をいただければ幸いです。おかげ

は、それが私の流星学ぶプロジェクトをフォークすることで動作させること自由に感じています。非常に貪欲になるでしょう。 - https://github.com/devin6391/meteorLearn1/tree/master/recipebook

答えて

1

export const RecipesCollection = new Mongo.Collection('recipes'); 

してから、コレクションの名前を使用します。私はこのようなエクスポートを使用することを行うには

流星パッケージのバージョンの問題 - 'accounts-ui'有名なCDNの問題のため、パッケージがインドでアップグレードされないことがあります。

それでも、コレクションは自身で作成されません。私はmongoDBコンソールに行って自分で作成しなければなりませんでした。その後、自動フォームのみ投稿されました

0

/server/main.jsでなぜか再インポート流星/流星?これは再びあるとしてこれを非常に恥ずかしい.... [OK]を解く

{{> quickForm collection="RecipesCollection" id="insertRecipeForm" type="insert" class="new-recipe-form" }} 
+0

私は流星/流星を逆輸入していません。 es6モジュールシステムごとに違ったファイルに対応しています。 また、RecipesCollectionをウィンドウやテンプレートの変数ではなく、モジュールの変数として直接使用することはできません。 –

+0

- それを試みました。あなたは複数の流星/流星の輸入について正しいですが。私はそれを修正した。 RecipesCollectionコレクションは、ウィンドウスコープ内にないので、Quickformに直接入れることはできません。 –