This code is trying to add a document to a collection by making a Meteor.call, But I need to wait for the results of ActiveTask.insert(doc);
in the server code before the next line gets executed by the compiler because it runs another code which depends of the value being inserted in the collection ActiveTask.
Is this possible and how? Thanks
client.js
Template.mainMenu.events({
'click .menuItem': function () {
var menuShortName = this.menuShortName;
Meteor.call('addAction', {'action': menuShortName});
server.js
Meteor.methods({
addAction: function (doc) {
ActiveTask.remove({});
doc.createdAt = new Date();
ActiveTask.insert(doc);
}
});