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.
All the updates I do are one at a time, but what's nice for me is that they are synchronous. =)
It seems you can bulk load though with the mongoimport tool: http://docs.mongodb.org/manual/reference/mongoimport/#cmdoption-mongoimport--upsertFields. You can do bulk upserts that way.
Otherwise I don't believe you can do it in one command via a client.