【发布时间】:2020-09-23 13:00:48
【问题描述】:
我有以下文件
{store : {
id : 'STORE1',
name : 'Electronics Store',
locations : [
{
id : 'LOC1',
quantity : 4
},
{
id : 'LOC2',
quantity : 10
},
{
id : 'LOC3',
quantity : 5
}
]
}
}
我想根据 id 字段使用 $inc 更新 locations 数组的多个元素的 quantity。
例如,我想用 +5 更新 id : 'LOC1' 到 quantity 字段,并用 +2 更新 id : LOC3 到它的 quantity 字段。
是否可以在 mongodb 中使用一个查询而不是对每个位置使用多个查询。
【问题讨论】:
-
这能回答你的问题吗? arrayFilters in mongodb --> 直接复制,只有
$set改成$inc
标签: mongodb mongodb-query