Why getting error
MongoError: multi update only works with $ operators
while using bulk find and update
to update multiple document.
Tried :
var bulk = db.collection('users').initializeUnorderedBulkOp();
var emails = ['a@gmail.com', 'b@gmail.com', 'c@gmail.com'];
var allStatus = ['s1', 's2', 's3'];
for (var i =0; i< allStatus.length; i++) {
var query = { email: emails[i], status: { '$ne': allStatus[i] } };
var updateField = {
$set: {status: allStatus[i], date: new Date()},
$push: {
notes: {note: 'jdf'+i, date: new Date()},
history: {status: allStatus[i], date: new Date()}
}
};
bulk.find(query).update(updateField);
}
bulk.execute();
via Shaishab Roy
No comments:
Post a Comment