[英]How to update an array of multiple elements in mongodb..?
我需要更新多個元素的數組。
{
"_id" : ObjectId("53e87e239ae974e6a0a81004"),
"name" : "mulagala",
"notifications" : [
{
"name" : "apple",
"status" : 0
},
{
"name" : "microsoft",
"status" : 0
},
{
"name" : "android",
"status" : 0
}
]
}
現在我想更改數組的每個狀態元素應更改為1,即。 status:1
個查詢。
我嘗試了以下方式
db.mystatus.update({'notifications.status':0},{$set:{'notifications.$.status':1}},false,true)
但是只有第一條記錄正在更新,該怎么辦。將尋求任何幫助!
您是否嘗試使用$運算符更新數組的元素? 當前,由於索引被編碼為0,因此它僅更新一個元素。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.