I am new to meteor and mongo db. I am making an application using [email protected]. I am making a file named '/imports/api/collections/recipe.js'. Here I am creating a collection and importing this file into both '/server/main.js' and '/client/main.js'. In recipe.js only I am publishing the Recipe collection and then in my client's file I am subscribing to it. Till this point everything is correct. Then I create a form using autoform, which works well and is created. But this form never gets posted.
First of all, my assumption was that when server starts, then at that point my db should have created a collection named recipe, but it doesn't.
Secondly, why autoform is not working? I think its because of first reason.
On client side, I get to see my recipe collection through Mongol(of meteor-toys).
My recipe file- '/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;
My server's file: '/server/main.js':
import { Meteor } from 'meteor/meteor';
import '/imports/startup/server/start.js';
import '/imports/api/collections/recipe.js';
My client's js file:
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;
}
});
New Recipe template:
<template name="NewRecipe">
<div class="new-recipe-container">
{{> quickForm collection=recipesCollection id="insertRecipeForm" type="insert" class="new-recipe-form" }}
</div>
</template>
I am using packages: Collection2 and autoform. Any help or suggestion would be appreciated. Thanks
Feel free to make it work by forking my meteor learn project. Would be very greateful. - https://github.com/devin6391/meteorLearn1/tree/master/recipebook
ok solved....Very ashamed of this as this is again a version issue with a meteor package - 'accounts-ui'. Sometimes packages do not get upgraded in India due to the famous CDN issue.
Still, collection do not get created by itself. I had to go to mongoDB console and create it by myself. Then only autoform posted to it
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With