流星集合在启动时未自动创建,并且自动表单不会发布到 mongo db



我是新来的流星和蒙古db。我正在使用meteor@1.3.4.1应用程序。我正在制作一个名为"/imports/api/collections/recipe.js"的文件。在这里,我创建了一个集合,并将该文件导入'/server/main.js'和'/client/main.js'。在Recipe .js中,只有我在发布Recipe集合,然后在我的客户端文件中订阅它。到目前为止,一切都是正确的。然后我使用autoform创建一个表单,它运行良好,并且已经创建。但是这个表单永远不会被发布。

首先,我的假设是,当服务器启动时,那么在这一点上我的数据库应该创建了一个名为recipe的集合,但它没有。

其次,为什么自动表单不起作用?我认为是第一个原因。

在客户端,我可以通过Mongol(流星玩具)查看我的食谱集。

我的配方文件- '/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和autoform。任何帮助或建议将不胜感激。由于

请随意通过fork我的meteor learn项目使其工作。那太好了。——https://github.com/devin6391/meteorLearn1/tree/master/recipebook

解决....非常惭愧,因为这又是一个流星包的版本问题- 'accounts-ui'。由于著名的CDN问题,有时包在印度无法升级。

仍然,集合本身不会被创建。我必须去mongoDB控制台并自己创建它。然后只有自动表单贴在上面

为什么要在/server/main.js中重新导入meteor/meteor ?

要做到这一点,我使用导出,像这样:
export const RecipesCollection = new Mongo.Collection('recipes');

,然后使用集合的名称:

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

最新更新