Meteor-Community-Packages / meteor-collection-hooks

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

after.insert() and MongoDB $inc modifier #128

Closed Jehu closed 9 years ago

Jehu commented 9 years ago

With this code i get an increment of 2 instead of 1

Streets.after.insert(function (userId, doc) {
  Territories.update({
    _id: doc.territory_id
  }, {
    $inc: {streets_count: 1}
  })
});

... while the code below entered in browser console increments by 1 like expected:

Territories.update({_id: "kdo5aSa8XrsirK6Ar"}, { $inc: {streets_count: 1 } })

A console.log inside of after.insert() fires just one time by the way.

Here a list of installed packages:

aldeed:autoform          5.3.0  
aldeed:simple-schema     1.3.3  
fastclick                1.0.3  
ground:db                0.3.9  
iron:layout              1.0.8  
iron:router              1.0.9  
matb33:collection-hooks  0.7.13 
meteor-platform          1.2.2  

I've testet without ground:db too. Same results. What is going wrong here?

rclai commented 9 years ago

What happens when you put that hook in the server only?

Jehu commented 9 years ago

@rclai if i restrict the hook to server or client only, $inc works as expected. Thank you.