如何在mongodb中更新此订单状态?这里一个订单Id和产品在一个数组中,在poduct对象中包含状态


{
"_id" : ObjectId("60e1db6c8418dc720d9bf38b"),
"products" : [
{
"pid" : ObjectId("60da10e21b35eb7e76a2a0d6"),
"qty" : 1,
"productname" : "Lives all product check",
"pType" : "SHOE",
"prize" : 44,
"total" : 42,
"status" : "Orderd",
"orderDate" : "Sunday, July 4, 2021",
"shipDate" : "",
"expDelivery" : "Sunday, July 11, 2021",
"DeliveredDate" : ""
}
],
"payment" : "cashonDelivery",
"totalOfOrder" : 42,
"placedDated" : "Sunday, July 4, 2021",
"shippingCharg" : 120,
"__v" : 0
}`

*如何在mongodb中更改对象值的数组我需要用猫鼬改变我的产品状态。我对没有任何作用

*

演示-https://mongoplayground.net/p/daKaNGE7W5E

使用$[<identifier>]

过滤后的位置运算符$[]标识与更新操作的arrayFilters条件匹配的数组元素

db.collection.update({},
{  $set: { "products.$[p].status": "delivered" } },
{  arrayFilters: [ { "p.pid": ObjectId("60da10e21b35eb7e76a2a0d6") } ]}
)

相关内容

最新更新