更改我所有文档的嵌套文档值 [英] Change all my documents nested document value

查看:64
本文介绍了更改我所有文档的嵌套文档值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在mongos shell中,我将如何遍历并将reviews.category中的每个文档更改为类别2"

In mongos shell how would I go through and change every document in reviews.category to "category 2"

我的文档结构:

{
   "_id": ObjectId("4fb3f443b1445d24fc000000"),
   "reviews": {
     "0": {
       "category": "category 1"
    },
     "1": {
       "category": "category 1"
    },
     "2": {
       "category": "category 1"
    },
     "3": {
       "category": "category 1"

    } 
  }
}

推荐答案

您将必须在应用程序代码中自行执行此操作,方法是查询文档并遍历所有嵌套的文档;然后将其保存回MongoDB.

You will have to do this yourself in your application code, by querying the document, and looping over all of your nested documents; and then save it back to MongoDB.

为了防止出现这种情况,请查看比较和交换部分,网址为 http://www.mongodb.org/display/DOCS/Atomic+Operations

In order to prevent race conditions with this, please have a look at the section compare and swap at http://www.mongodb.org/display/DOCS/Atomic+Operations

当前有一个打开的票证可将此功能添加到MongoDB.您可能需要对其进行投票: https://jira.mongodb.org/browse/SERVER-1243

There is currently an open ticket for this to add this functionality to MongoDB. You might want to up-vote it: https://jira.mongodb.org/browse/SERVER-1243

这篇关于更改我所有文档的嵌套文档值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆