Don't think this is at all possible but wanted to check.
If I have the following documents:
doc1 : {
_id: 1,
name: 'John Smith',
age: 20
}
doc2 : {
_id: 2,
name: 'Jane Smith',
age: 22
}
I want the client to be able to pass me both docs in the same request for update. In this case maybe add an address to both docs.
Is there a way the I can send one update statement to mongo such that it updates both of the documents with the name values?
I.E. from client:
doc1 : {
_id: 1,
name: 'John Smith',
age: 20,
address: '123 Street'
}
doc2 : {
_id: 2,
name: 'Jane Smith',
age: 22,
address: '456 Way'
}
Currently I am iterating over the values and updating one at a time. Problem with that is mongoose/mongodb updates are async, so I cannot reliably tell the client that I updated each result until all update callbacks have fired. I have a counter to make sure I receive N number of callbacks then I send a response.
asynclibrary for ways to improve on the callback counter approach.multi:trueflag forupdate().