I am learning mongodb and am trying to perform a simple multi documents update with the {$multi: true} option, but it only updates a single document.
> db.users.update({'color': 'black'}, {$set: {'title': 'blackers'}}, {$multi: true});
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.users.find({'color': 'black'});
{ "_id" : ObjectId("5562312f061fa19e6cebc7e4"), "color" : "black", "hobby" : [ "dancing", "breaking", "drawing", "praying", "smiling" ], "name" : "john", "schools" : [ "mlimwa", "martin", "ignatus", "eget", "jubilee", "canon" ], "title" : "blackers" }
{ "_id" : ObjectId("5564057bb0f557f0c0589e66"), "color" : [ "black" ], "name" : "demo" }
{ "_id" : ObjectId("556424fc1dd78ab02dd2918f"), "color" : "black", "name" : "tola" }
>db.version()
3.0.3
Please help am really stuck..
It is not $multi
, write only {multi:true}
db.users.update({'color': 'black'}, {$set: {'title': 'blackers'}}, {multi: true});
refer the documentation here, for further help, regarding upsert, or writeconcern params http://docs.mongodb.org/manual/reference/method/db.collection.update/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With