Reputation: 24583
So after posting some other questions and doing some research it does not look like it is possible to update multiple documents with different data in the same call to mongodb.
doc1 : {
_id: 1,
name: 'John Smith'
}
doc2 : {
_id: 2,
name: 'Jane Smith'
}
So if the client passes both docs to the server adds an age field and wants a response back from the server when both have been updated I have to wait for two update callbacks to return.
Not a huge deal at all as there look to be some good async modules out there like Step and Async. However I am using Mongoose already. I see that there are promises in mongoose. Looking at the docs I don't think this is possible but it may be that I just don't understand.
Using mongoose can I submit N number of updates to mongo and know when all N have completed so I can response to the client. Without a counter of course (as that is what I am already doing).
Thanks!
Upvotes: 0
Views: 101
Reputation: 1857
As you said, you can use promises. I haven't tried doing this myself, but it looks like you may be able to use Promise.then
, although it means you will be sequencing your queries instead of submitting them all at once like you are now.
Link: http://mongoosejs.com/docs/api.html#promise_Promise-then
Upvotes: 0
Reputation: 1557
I believe not, instead use async (or possibly step, i'm not familiar) to run multiple queries/queries multiple times.
Upvotes: 1