[英]Mongoose : Find and Update Multiple Nested Documents
My Documents are as follows.我的文件如下。
{
"order_id" : "1",
"payment_status" : false,
"items" : [
{
"item_id" : 1,
"payment_status" : false,
},
{
"item_id" : 2,
"payment_status" : false,
},
{
"item_id" : 3,
"payment_status" : false,
},
]
}
I need to update the fields payment_status
for {"order_id":1}
and {"item_id" : 1}
and {"item_id" : 3}
.我需要更新
{"order_id":1}
和{"item_id" : 1}
和{"item_id" : 3}
的字段payment_status
。 Also, I need to update the same in bulk for matching conditions.此外,我需要批量更新相同的匹配条件。 Is this possible in mongoose?
这在猫鼬中可能吗?
You want to be using $arrayFilters like so:你想像这样使用$arrayFilters :
db.collection.updateMany({
"order_id": "1"
},
{
"$set": {
"items.$[item].payment_status": true
}
},
{
arrayFilters: [
{
"item.item_id": {
$in: [
1,
3
]
}
}
]
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.