[英]How to update nested array document in mongodb
我有一個集合看起來像
{
"Aid":12234,
"items":{
"itemId":"SP897474",
"Blocks":[
{
"blockId":"W23456",
"name":"B1",
"innerBlock":[
{
"id":"S23490",
"name":"IB1",
"state":true
},
{
"id":"S23491",
"name":"IB2",
"state":true
},
{
"id":"S23492",
"name":"IB3",
"state":true
}
],
"active":true
},
{
"blockId":"W23457",
"name":"B2",
"innerBlock":[
{
"id":"S23482",
"name":"IB1",
"state":true
},
{
"id":"S23483",
"name":"IB2",
"state":true
}
],
"active":false
}
]
},
"active":true
}
由於嵌套,我無法更新innerBlock數組的字段,特別是名稱,狀態。 基本上,我想更新提到的字段。我已經嘗試過這個查詢
User.update({
"items.Blocks.innerBlock.id": req.body.id,
"Aid": req.body.Aid
}, {
"$set": {
"items.Blocks.$.InnerBlock.$.name": req.body.name
}
})
它顯示了下面給出的錯誤
"errmsg": "Too many positional (i.e. '$') elements found in path 'items.Blocks.$.InnerBlock.$.name'"
我不知道如何修復它。在mongo shell中可以查詢什么? 謝謝。
現在只有一個位置運算符可用於mongoDB。 有https://jira.mongodb.org/browse/SERVER-831打開功能請求
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.