I have a document containing lists. Assume that they:
[ { _id: 52b37432b2395e1807000008, name: ListA, order: 1, desc: 'More about List A' }, { _id: 52b37432b2395e1807000009, name: LISTB, order: 2, desc: 'More about List B' }, { _id: 52b37432b2395e180700000e, name: LISTC, order: 3, desc: 'More about List C' }, { .. } ]
Now I want to change my order field using a batch update. I have updated order JSON
var updated_stage = [{_id: '52b37432b2395e1807000008', order:2},{_id: '52b37432b2395e180700000e', order:1}, {_id: '52b37432b2395e1807000009', order:3}]
Now I need to update the LIST model in Mongoose with the new array that I have. I know that I can update multiple documents with the same value using batch update
Model.update({ }, { $set: { order: 10 }}, { multi: true }, callback);
But I have to update them with different values. How am I supposed to do this? What is the most effective way?
Devesh kumar
source share