Meteor-Community-Packages / meteor-collection-hooks

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

insert in .after.insert runs twice #104

Closed alexedev closed 9 years ago

alexedev commented 9 years ago

If we call Collection.insert(smth) in .after.insert then that smth is inserted twice. This strange behavior happens only if .after.insert is accessible from both client and server.

wursttheke commented 9 years ago

We experienced the same thing. There was a little discussion on the forum:

It seems that the hooks are not run inside the method call, which meteor uses internally when you do a raw insert on the client. To circumvent the problem, we wrap our insert call inside a meteor method.

So, ideally the hooks should be part of the 'native' meteor insert, update, etc. calls. But I guess this can only be done by altering the core. So I'm referencing this highly requested feature again. :wink:

alexedev commented 9 years ago

I ended up putting the code in /server , because I do not care for latency compensation in my specific case.

matb33 commented 9 years ago

The hooks aren't particularly smart -- they just run before/after your call to Collection.insert. If you execute Collection.insert on the client and the server, the hooks will get called twice: once on the client, once on the server.