Hi I am using meteor-collection2 with mdg:validated-method. Below is my code:
Posts.schema = new SimpleSchema({
title: {
type: String
},
description: {
type: String
},
posted: {
type: Date,
autoValue: function(): Object {
console.log("setting date:" + this.isInsert + this.isUpsert);
return new Date();
}
}
});
Posts.attachSchema(Posts.schema);
Here is my Validated method:
export const addPost = new ValidatedMethod({
name: 'Posts.addPost',
validate: Posts.schema.validator({ clean: true, filter: false }),
run(post) {
if (!this.userId)
throw new Meteor.Error('403', 'You must be logged-in to reply');
Posts.insert({
title: post.title,
description: post.description,
});
}
});
Issue is i am seeing 3 console logs on client with below information:
setting date:undefinedundefined
setting date:truefalse
setting date:truefalse
and 2 console logs on server
setting date:undefinedundefined
setting date:truefalse
I have following questions:
- Why i am seeing multiple console logs (3 on client and 2 on server)
- why this.isInsert and this.isUpsert are undefined for the first time