Meteor-Community-Packages / meteor-collection-hooks

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

will Collection.before 'update' abort Collection update ? #4

Closed crapthings closed 11 years ago

crapthings commented 11 years ago
Organizations.before 'update', (userId, options) ->
    options.updatedAt = new Date()
    options.timestamp = Date.now()

Meteor.methods

    editOrganization: (options, organizationId) ->
        if isAdmin() and typeof options is 'object' and organizationId
            Organizations.update _id: organizationId,
            $set: options

this is my code.

but update method didn't update document at all

matb33 commented 11 years ago

The function signature for before update has to match the one for the update call:

Organizations.before("update", function (userId, selector, modifier, options) {
  modifier.$set.updatedAt = new Date();
  modifier.$set.timestamp = Date.now();
});
crapthings commented 11 years ago

Awesome, it works.