{
"_id": "chat",
"toList": [
{
"_id": "person 1",
"messages": {
"_id": "1",
"message": "Message from person 1"
}
},
{
"_id": "Person 2",
"messages": [
{
"_id": "1",
"message": "Message from person 2"
},
{
"_id": "2",
"message": "new message"
}
]
}
]
}
嗨,这是我的db客户文档。我想更改(更新)消息属性值从“新消息”到“来自人2的新消息” “ messages._id
“:”{2}“”toList._id
“:”人2“。请帮我找到合适的解决方案。
我的代码:
db.customers.update({"_id":"Chat", "toList._id":"Person 2", "toList.messages._id":"2"},{$set:{"toList.$.messages.message":"new message from person 2"}}, function(err, res)
{
console.log(res);
});