【发布时间】:2012-11-08 07:50:21
【问题描述】:
为什么getLastError 显示没有更新文档?
> db.contacts.find()
{ "_id" : ObjectId("509b60e7c546b6dc73f57877"), "name" : "mike" }
> db.contacts.update({}, {name: 'peter'})
> db.runCommand({getLastError: 1})
{ "n" : 0, "connectionId" : 3188, "err" : null, "ok" : 1 }
> db.contacts.find()
{ "_id" : ObjectId("509b60e7c546b6dc73f57877"), "name" : "peter" }
getLastError 正在返回 n: 0,即使文档已明确更新。它也缺少updatedExisting 字段。我在一个示例 MongoHQ 数据库上远程运行它。
针对我的本地 MongoDB 实例运行,getLastError 正确返回:
> db.runCommand({getLastError: 1})
{
"updatedExisting" : true,
"n" : 1,
"connectionId" : 1,
"err" : null,
"ok" : 1
}
【问题讨论】:
-
当我使用 2.0 版本的 Mongo shell 和 2.2 数据库时,这似乎发生在我身上。可以试试用 2.2 或 2.2.1 版本的 shell 运行吗?