I was trying the following Meteor method, but it seems it is not working. Because when I check my DB, I cannot find the updated information.
const Employees = new Mongo.Collection("Employees");
Employees.attachSchema(Schemas.Employee, { selector: { type: "fullTime" } });
Employees.attachSchema(Schemas.EmployeeVariant, { selector: { type: "partTime" } });
Meteor.methods({
"employees/updateTasks": function (employeeId, taskId) {
this.unblock();
//the following is printed.
console.log("employeeId: "+employeeId+" taskId:"+ taskId);
return Employees.update({_id: employeeId},
{$push: {tasks: taskId}},
{selector: {type: "fullTime"}});
}
});
Is there anything obvious wrong here?
Another question is:
Sometimes I see people using it this way:
Employees.update(employeeId, // not {_id:employeeId}
{$push: {tasks: taskId}},
{selector: {type: "fullTime"}});
It is being used here: "5.3 Add event handlers for Task buttons"
Why is this?
My Mongodb's version is 3.2.6
It turns out that collection hooks (https://github.com/matb33/meteor-collection-hooks) are used here. There is a Employees.before.update method to check what to do before "Employees.update" really happens.