-
-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When the selector is not an id (= server side), does the after.update hook work? #38
Comments
Are you saying |
Exactly.
Collection.update({foo:"xyz"},{$set:{foo:"abc"}},{multi:true})
does the update and triggers before.update but not after.update
That's why I did: Collection.find({foo:"xyz"}).forEach(function(col){ Collecion.update(col._id,{$set:{foo:"abc"}}) }) so that both, before and after, are triggered |
Same issue here. What I'm doing is this: test.after.update(function (userId, doc) {
var x = 1;
test.update({ _id: doc._id }, { $set: { x: x } });
}); |
@gabrielhpugliese if |
Lol yeah, true story. I think the buffer just exploded. Anyway, how can we node: ../src/node_object_wrap.h:60: static T* Gabriel Pugliese On Wed, May 7, 2014 at 9:32 PM, Andrew Mao notifications@github.com wrote:
|
I think I need a rest :( |
I am extremely confused by your penultimate post. |
After you saying about the loop, I've checked my Meteor console and it was raising this error (probably because of the loop): But, disconsider that, please. Sorry for that. |
I'm unable to reproduce this. I even added https://github.com/matb33/meteor-collection-hooks/blob/master/tests/update_without_id.js |
Can you show us more of your code? I suspect you are trying to modify the doc in the after update by either setting a property on doc (which won't work) or running an update again (which may go into an infinite loop without the right guards in place) |
I tried out and reproduced it. https://github.com/darkship/collection_hooks_bug_after_update. I noticed that it didn't happened in every case. |
@darkship I cloned your repo and got the example running. I am able to click on the +1 button of any and they increment accordingly, eventually all falling into step and incrementing together. Looks like it's working perfectly. I noticed some remnants of Collection2 in there. Do you have it enabled when it fails for you? |
I tried with both, it had the same effect. When you say it's working, did you see any logs? When you click on "+1" the update is done but I never see the "after" in the server console, only the before. coll.before.update(function(userId, doc, fieldNames, modifier, options){ console.log("before",doc.count) }) coll.after.update(function(userId, doc, fieldNames, modifier, options){ console.log("after",doc.count) }) |
OK I understand what's going on. The problem is that the after hook has no idea which documents you're referring to anymore because your original selector no longer matches any documents after the update occurred. For example, let's say your selector used to determine which docs to update is I'm not sure how to proceed. Any ideas? |
Don't we have the |
I think we do! Good call, gonna try |
While you're thinking about that, do you think it would be possible to short circuit the per-document One can also use the direct operations if they realize this, of course. |
That looks right as long as it works :) |
thanks! |
Can you please (please!) can take a quick look on my reproduction? You can clone and just mrt then click on button to create/update the only one doc. If I change the after to before it works ok. |
@gabrielhpugliese you can't modify the document after the update has already occurred. You'll need to do that in a before hook. If you really want to run an update after an update, you could use the new |
Hmmmm, I see. Gonna do that on before hook, then. Many thanks. |
Did someone try it ? Or is it a case where the hooks isn't supposed to work?
When my selector wasn't an Id, my data was updated but my after.update hook wasn't called, so I updated one document after an other to trigger the hook.
Note : before.update is Ok
The text was updated successfully, but these errors were encountered: