Meteor-Community-Packages / meteor-collection-hooks

Meteor Collection Hooks
https://atmospherejs.com/matb33/collection-hooks
MIT License
657 stars 92 forks source link

Accessing nested field in fieldNames when using before.update hook #162

Closed nabiltntn closed 8 years ago

nabiltntn commented 8 years ago

Hi, When using the before update hook with a nested update like this: collection.update({_id : 'dddddd'},{$set : {'parentProp.child1' : true}});

fieldNames inside collection.before.update(function(userId, doc, fieldNames, modifier, options) { }); does not contain full property path : parentProp.child1 but only parentProp

javierocanas commented 8 years ago
collection.before.update(function(userId, doc, fieldNames, modifier, options){
  modifier.$set = modifier.$set || {};
  modifier.$set.parentProp = {child1:true};
})

Good vibes.

matb33 commented 8 years ago

I mimicked what Meteor does in their Allow/Deny API, and lifted their function to get the fieldNames. I'll be sticking with this for the foreseeable future since it matches an existing similar Meteor API