Comments (23)
Are you saying before.update
runs for all the documents but after.update
does not?
from meteor-collection-hooks.
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
from meteor-collection-hooks.
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 } });
});
from meteor-collection-hooks.
@gabrielhpugliese if after.update
was working as advertised, your code would result in an infinite loop.
from meteor-collection-hooks.
Lol yeah, true story. I think the buffer just exploded. Anyway, how can we
handle the issue now? I really need the after.update
node: ../src/node_object_wrap.h:60: static T*
node::ObjectWrap::Unwrap(v8::Handlev8::Object) [with T = node::Buffer]:
Assertion `!handle.IsEmpty()' failed
Gabriel Pugliese
CodersTV.com
@CodersTV
On Wed, May 7, 2014 at 9:32 PM, Andrew Mao [email protected] wrote:
@gabrielhpugliese https://github.com/gabrielhpugliese if after.updatewas working as advertised, your code would result in an infinite loop.
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/38#issuecomment-42501125
.
from meteor-collection-hooks.
I think I need a rest :(
from meteor-collection-hooks.
I am extremely confused by your penultimate post.
from meteor-collection-hooks.
After you saying about the loop, I've checked my Meteor console and it was raising this error (probably because of the loop):
node: ../src/node_object_wrap.h:60: static T* node::ObjectWrap::Unwrap(v8::Handle<v8::Object>) [with T = node::Buffer]: Assertion
!handle.IsEmpty()' failed`
But, disconsider that, please. Sorry for that.
I'm just facing the same problem as @darkship - after.update is not working as I expected. I'm trying to update doc.x = x;
and it's not saving to db.
from meteor-collection-hooks.
I'm unable to reproduce this. I even added multi: true
and still no luck reproducing -- test passes. Perhaps you can modify the test until it fails? It's in the master branch:
https://github.com/matb33/meteor-collection-hooks/blob/master/tests/update_without_id.js
from meteor-collection-hooks.
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)
from meteor-collection-hooks.
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.
coll.update({random:i},{$inc:{random:1}},{multi:true}) -> fails to trigger after.update
coll.update({random:{$gt:i}},{$inc:{random:1}},{multi:true}) --> triggers after.update
from meteor-collection-hooks.
@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?
from meteor-collection-hooks.
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) })
from meteor-collection-hooks.
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 {random: 76}
. Let's say that matches 50 documents, and proceeds to run your update that increments the value of random
by 1. Now all those 50 documents have the value of 77
for the field random
. After the update has finished, meteor gives me back the number of affected documents (50), nothing else -- no ids. The "after" code tries to find these documents and call the after
hook for each of them. It tries to use the original selector {random: 76}
but of course this won't match anything -- all the values for random are now 77
.
I'm not sure how to proceed. Any ideas?
from meteor-collection-hooks.
Don't we have the _id
s from the find operation that was run?
from meteor-collection-hooks.
I think we do! Good call, gonna try
from meteor-collection-hooks.
While you're thinking about that, do you think it would be possible to short circuit the per-document update
/remove
if no hooks are installed for a collection? It just seems awfully inefficient to use the find and per _id
update if it doesn't need to be done.
One can also use the direct operations if they realize this, of course.
from meteor-collection-hooks.
@mizzao sure thing. I'm assuming I did what you meant: f1d2ac6
from meteor-collection-hooks.
That looks right as long as it works :)
from meteor-collection-hooks.
thanks!
from meteor-collection-hooks.
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.
https://github.com/gabrielhpugliese/after-hook-test/blob/master/after-hook-test.js
If I change the after to before it works ok.
from meteor-collection-hooks.
@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 collection.direct.update
from meteor-collection-hooks.
Hmmmm, I see. Gonna do that on before hook, then. Many thanks.
from meteor-collection-hooks.
Related Issues (20)
- More explanation of 0.9.0 breaking changes please HOT 5
- How i can extend ALL collections? HOT 6
- After fetch hook? HOT 3
- An after.update hook's modifier doesn't get a before.update's updated modifier
- Add GitHub actions for CI HOT 2
- Using direct still causes fetchPrevious behaviour on update method
- hook "remove" does not remove hook or removes wrong hook HOT 1
- bulk update didnt trigger after update hooks HOT 3
- attach hooks to raw collections HOT 3
- Meteor 2.6: after.insert callback does not contain correct document _id HOT 2
- problem after insert doc._id object HOT 4
- Support to Meteor 2.8 and Mongo async methods HOT 5
- After update hook does not use direct find HOT 2
- Async hooks run in parallel to the collection operation HOT 3
- Meteor 3.0 migration considerations HOT 1
- Ability to add call-level parameters to hooks HOT 1
- Core dump at Meteor 3.0 alpha 15: node: ../src/coroutine.cc:134: void* find_thread_id_key(void*): Assertion `thread_id_key != 0x7777' failed. HOT 2
- Calling Meteor.userAsync inside pub throws an error in meteor 3 beta HOT 3
- before hooks and async callbacks are not compliant with Meteor 3 promises HOT 4
- Throw in before.* should also cancel the operation HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from meteor-collection-hooks.