【问题标题】:How to return number of updated objects in mongodb?如何在 mongodb 中返回更新对象的数量?
【发布时间】:2011-01-04 18:07:34
【问题描述】:

我正在更新 mongodb 中的多个元素。是否可以返回受影响对象的数量?

【问题讨论】:

    标签: mongodb mongodb-query


    【解决方案1】:

    使用 getLastError。 n 键将包含更新文档的数量

    > db.count.update({x : 1}, {$inc : {x : 1}}, false, true)
    > db.runCommand({getLastError : 1})
    {
    "err" : null,
    "updatedExisting" : true,
    "n" : 5,
    "ok" : true
    }
    

    请注意,这会运行“getLastError”命令,该命令返回更新命令完成后的行数。

    数据库命令是listed here

    【讨论】:

    • 你知道 getLastError 返回的这些字段记录在哪里吗?
    猜你喜欢
    • 2015-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-21
    • 2021-12-29
    • 2021-09-27
    相关资源
    最近更新 更多