整个操作过程的代码:
Microsoft Windows [版本 10.0.10586] (c) 2015 Microsoft Corporation。保留所有权利。 C:\WINDOWS\system32>net start mongodb MongoDB 服务正在启动 . MongoDB 服务已经启动成功。 C:\WINDOWS\system32>E: E:\>cd MongoDB\Server\3.2\bin E:\MongoDB\Server\3.2\bin>mongo.exe MongoDB shell version: 3.2.6 connecting to: test Server has startup warnings: 2016-05-05T11:35:23.926+0800 I CONTROL [main] ** WARNING --jsonp is specified without --httpinterface, 2016-05-05T11:35:23.926+0800 I CONTROL [main] ** enabling http interface > db.dogs.find() { "_id" : ObjectId("572aac0c25e0b96bc50f36ea"), "name" : "wang" } { "_id" : ObjectId("572aac1025e0b96bc50f36eb"), "name" : "li" } { "_id" : ObjectId("572aac3b25e0b96bc50f36ec"), "name" : "li", "age" : 1 } > db.dogs.update({'name':'wang'},{$set:{'name':'jack'}}) WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 }) > db.dogs.update({'name':'li'},{$set{'age':9}}) 2016-05-05T11:52:12.494+0800 E QUERY [thread1] SyntaxError: missing : after property id @(shell):1:34 > db.dogs.update({'name':'li'},{$set{'name':'wangwang'}}) 2016-05-05T11:52:36.569+0800 E QUERY [thread1] SyntaxError: missing : after property id @(shell):1:34 > db.dogs.find() { "_id" : ObjectId("572aac0c25e0b96bc50f36ea"), "name" : "jack" } { "_id" : ObjectId("572aac1025e0b96bc50f36eb"), "name" : "li" } { "_id" : ObjectId("572aac3b25e0b96bc50f36ec"), "name" : "li", "age" : 1 } > db.dogs.update({"name":"jack"},{$set:{"name":"think"}}) WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0, "writeError" : { "code" : 10003, "errmsg" : "Cannot change the size of a document in a capped collection: 37 != 38" } }) >
第一次更新时通过,第二次更新故意写错,第三次正确更新,更新失败。