我有以下收藏,我有一個問題:
{
"_id" : ObjectId("123456789"),
"user_id" : 123456,
"total" : 100,
"items" : [
{
"item_name" : "my_item_one",
"price" : 30
},
{
"item_name" : "my_item_two",
"price" : 30
},
{
"item_name" : "my_item_three",
"price" : 30
}
]
}
我如何同時更新所有價格,(所有物件的價格=50)感謝幫助
uj5u.com熱心網友回復:
您可以使用位置 all 運算子來更新陣列中的所有元素
db.collectionName.update(
{ },
{ $set: { "items.$[].price" : 50 } },
{ multi: true }
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/321563.html
