Reputation: 250
I am new to meteor and autoform and am trying to get a form to insert into mongo. No matter what I have changed it just will not work. I have no idea what to try next.
I have removed insecure and autopublish. Attached is a link to my .js and my html file.
I have setup a scheme, gotten the form to show on the html perfectly. now when I hit submit nothing is being put into mongo. I have allow rules setup. I have a ton of console.logs displaying and they all trigger and follow along as if the post was successful. In fact in the onSuccess I get a document number yet there is nothing in my DB.
Any help here is greatly appreciated. I know it must be something small here but I have racked my brain for hours of endless searching.
.js file without the scheme. Full js file in the plnkr link
if (Meteor.isClient) {
// ********************************************************
// *** Creating the database scheme for the customer account
// ********************************************************
customers = new Mongo.Collection("customer");
AutoForm.debug();
var postHooks = {
before: {
insert: function(doc) {
console.log("Getting to posting hooks");
if(Meteor.userId()){
doc.createdUser = Meteor.userId();
doc.createdDate = Date();
console.log("Got to the insert before hook!");
}
return doc;
}
},
after: {
// Replace `formType` with the form `type` attribute to which this hook applies
insert: function(error, result) {
console.log("Getting to the after insert function");
console.log(error);
console.log(result);
console.log("New Document ID is " + this.docId);
}
},
onSuccess: function(formType, result) {
console.log("Getting to the insert sucess area");
console.log(result);
},
onError: function(formType, error) {
console.log(error);
}
}
AutoForm.addHooks('insertCustomer', postHooks);
Template.customerTemplate.helpers({
showLoginError: function(){
return showCustomerSaveError;
}
});
}
if (Meteor.isServer) {
customers = new Mongo.Collection("customer");
customers.allow({
insert: function (userId, doc) {
console.log("Getting to the insert server call");
// the user must be logged in
return !! userId;
},
update: function (userId, doc, fields, modifier) {
// can only change your own documents
return doc.owner === userId;
},
remove: function (userId, doc) {
// can only remove your own documents
return doc.owner === userId;
},
fetch: ['owner']
});
}
http://plnkr.co/edit/5pM0Co9luGLIBBNKP5YA
Upvotes: 0
Views: 258
Reputation: 5088
You're adding the file to the database but not publishing it.
Run meteor add autopublish
or check in MongoDB itself to see the document.
Upvotes: 1