javascript - how to update into nested in array in mongodb -


i have structure 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 unique in list array , id unique in card array.

i want insert 2 key value pair specific document of card array . example want add key value id number 1213

the out put should this

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

how update?

try mongodb positional operator.

your query list.$.id = 123


Comments