Meteor-Community-Packages / meteor-collection-hooks

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

before.update doc is old doc before updates? Or is doc the new doc as will be saved? #179

Closed ghost closed 8 years ago

ghost commented 8 years ago

I'd like to validate doc on before.update, but apparently doc is the old doc before the modifier is applied to it. How do we validate the new doc?

ghost commented 8 years ago

Answer: use LocalCollection from minimongo:

LocalCollection._modify(doc, modifier)

That modifies the doc in place, and then we can perform checks on it's new modified state.

matb33 commented 8 years ago

Yep... https://github.com/matb33/meteor-collection-hooks/issues/91#issuecomment-85007712