简体   繁体   English

如何更新到mongodb中的嵌套在数组中

[英]how to update into nested in array in mongodb

i have a structure like this 我有这样的结构

{

  "name":"xxxxxx",

  "list":[
           {

             "listname":"XXXXX1",
              "card":[
                       {
                         "title":"xxxxxx",
                         "descip":"xxxxxxxxxx",
                         "id":"1213"
                       },
                       {
                         "title":"xxxxxx",
                         "descip":"xxxxxxxxxx",
                         "id":"1214"
                       }

              ] 

           }, 
           {
              "listname":"xxxxxx2",
              "card":[
                       {
                          "title":"xxxxxx",
                          "descip":"xxxxxxxxxx",
                          "id":"1345",
                       },
                       {
                          "title":"xxxxxx",
                          "descip":"xxxxxxxxxx",
                          "id":"1346",
                      }

              ]

           }


   ]

}

here listname is unique in list array and then id is unique in card array. 这里listname在list数组中是唯一的,而id在card数组中是唯一的。

i want to insert extra two key value pair into specific document of card array . 我想在卡阵列的特定文档中插入额外的两个键值对。 example now i want to add extra key value into id number 1213 现在示例,我想向ID号1213中添加额外的键值

the out put should look like this 输出应该看起来像这样

              "card":[
                       {
                          "title":"xxxxxx",
                          "descip":"xxxxxxxxxx",
                          "id":"1213",
                          "name":"XXXXxx",
                           "age":"xxxx"
                       },
                       {
                          "title":"xxxxxx",
                          "descip":"xxxxxxxxxx",
                          "id":"1214",
                      }

                   ]

how to update? 如何更新?

Try mongodb positional operator. 尝试mongodb 位置运算符。

Your query will be like list.$.id = 123 您的查询将类似于list。$。id = 123

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM