Closed nate-strauser closed 10 years ago
if i have a hook like so:
Things.before.update(function (userId, doc, fieldNames, modifier, options) { modifier.$set.updatedAt = new Date(); });
an update like this works without checking/initing $set
Things.update({_id:"wAARchoDwYubfff2J"},{$set:{name:"updated"}});
but this does not
Things.update({_id:"wAARchoDwYubfff2J"},{$inc:{count:1}});
if $set is not used in the update, then it has to be initialized before it can be added to or altered
noted by AVITAL OLIVER during a review of this article - https://meteor.hackpad.com/Meteor-Cookbook-Using-Dates-and-Times-qSQCGFc06gH
Very good point, and I was surprised to find my example didn't already do this as it's the same pattern I use in my own code! Thanks for the contribution and attention to detail
if i have a hook like so:
an update like this works without checking/initing $set
but this does not
if $set is not used in the update, then it has to be initialized before it can be added to or altered
noted by AVITAL OLIVER during a review of this article - https://meteor.hackpad.com/Meteor-Cookbook-Using-Dates-and-Times-qSQCGFc06gH