Mongodb多重更新,仅更新mongo-shell中的单个文档

Arc*_*oob 3 mongodb mongo-shell

我正在学习mongodb,并尝试使用{$ multi:true}选项执行简单的多文档更新,但是它仅更新单个文档。

> 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
Run Code Online (Sandbox Code Playgroud)

请帮助,我真的卡住了..

Nis*_*ant 5

不是$multi,只写{multi:true}

db.users.update({'color': 'black'}, {$set: {'title': 'blackers'}}, {multi: true});
Run Code Online (Sandbox Code Playgroud)

请参阅此处的文档,以获取有关upsert或writeconcern参数的更多帮助,http: //docs.mongodb.org/manual/reference/method/db.collection.update/