[英]How to update the speicific field in array of objects in mongoose
Hi there i wanted to update status field in messages.您好,我想更新消息中的状态字段。 I'm trying to use
我正在尝试使用
db.messagev2.updateMany(
{
user1: 8, user2:150,
"messages.receiver":150,
"messages.status" : "sent",
},
{'$set': {'messages.$.status': "read"}},{multi:true})
but only the first status in message is updating.. Need help但只有消息中的第一个状态正在更新..需要帮助
You need to replace:您需要更换:
'messages.$.status'
with:和:
'messages.$[elem].status'
And add $arrayFilters:并添加 $arrayFilters:
{ arrayFilters: [ { "elem.receiver": 150 ,"elem.status": "sent"} ] }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.