Comments (5)
I'm trying to understand what you mean by this - if you're updating a bunch of documents using the same query and modifier with {multi: true}
- how/why would you have the ability to change the modifier mid-update?
You're certainly free to update/overwrite/cancel the modifier for each document's update (i.e. each iteration of the hook). And though likely not optimal for multiple documents, you can even query the database if you need current data from pervious iteration (e.g. counts, flags, etc.)
What's the use-case here?
BTW, there's no one really updating this package - you may want to try checking if there's any currently updated forks.
from meteor-collection-hooks.
@evolross — yep, totally understand that and I did end up manually iterating through each object and updating one by one. The problem is that the hook runs once per document that is updated — misleading the developer into thinking that it's a hook which is running for just a single document update.
I was more suggesting that it's made clear in the docs / readme, or the logic is changed to return a set of documents that will be affected by the modifier (rather than running the hook potentially thousands of times, once for each document...).
Appreciate the library isn't really maintained these days, though. Which is a shame, as Meteor is such a brilliant framework to work with! :)
from meteor-collection-hooks.
I just bumped into this in one of our apps. Here is the use case :
you use the before.update function to compute the field computed of the collection with something like:
field computed = field a + field b
Let's say you have two documents with b = 0
in one and b = 1
in the second and want to update a value in both items using one update with {multi:true}
. In this case, you want the computed field to be updated in both documents with the correct value => and this fails due to the behavior highlighted here.
Propositions of possible ways to fix the behavior of the package :
- when
{multi: true}
, call the before.update only once and not once per document. Add a mention of this in the documentation - when
{multi: true}
, call the before.update once per document and fix the update behavior (seems difficult and could lead to performance issues when updating a lot of docs, which is obviously why one would use{multi:true}
)
After having a look at the code, both options seems difficult to implement. The only simple thing is to add a note in the documentation
@StorytellerCZ what do you think ?
Thanks !
from meteor-collection-hooks.
Well, let's start with the note in the documentation to get the simple thing done. @vparpoil since you have broken it down, can you do the PR?
Honestly I prefer the first method better, even if it has its drawbacks and could potentially be breaking.
from meteor-collection-hooks.
Here is a try for an update to the documentation
If we want to avoid the multiple calls of before.update
function when using multi:true
, I think we will have to change the api for this case because the before.update
hook receive the document about to be updated as a parameter (doc
), and this won't be doable anymore. We could send either an array with the documents about to be updated, or null/undefined.
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.