繁体   English   中英

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

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

我有这样的结构

{

  "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",
                      }

              ]

           }


   ]

}

这里listname在list数组中是唯一的,而id在card数组中是唯一的。

我想在卡阵列的特定文档中插入额外的两个键值对。 现在示例,我想向ID号1213中添加额外的键值

输出应该看起来像这样

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

                   ]

如何更新?

尝试mongodb 位置运算符。

您的查询将类似于list。$。id = 123

暂无
暂无

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

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