我目前正在开发MongoDB。有一个条件我无法处理它。所以我需要你的帮助。
我的收藏数据就像,
{
"_id": ObjectId("59bb85ad7a64f91145db564e"),
"updatedAt": new Date(1505461677518),
"createdAt": new Date(1505461677518),
"player_detail": [
{
"_id": ObjectId("59bb85ad7a64f91145db564f"),
"name": "abcd",
"runs": [
{
"innings": "1st",
"run": "69",
"wicket": "2"
},
{
"innings": "2nd",
"run": "98",
"wicket": "3"
}
]
},
{
"_id": ObjectId("59bb85ad7a64f91145db564g"),
"name": "new player",
"runs": [
{
"innings": "1st",
"run": "70",
"wicket": "0"
},
{
"innings": "2nd",
"run": "111",
"wicket": "1"
}
]
}
]
}
现在我想更新播放器运行,这里条件就像,
59bb85ad7a64f91145db564e
abcd
1'st
此处集合名称为cricket
。我正在尝试使用像
cricket.findOneAndUpdate(
{
$and: [
{ _id: mongoose.Types.ObjectId('59bb85ad7a64f91145db564e') },
{ "player_detail.name": 'abcd' },
],
},
{
"player_detail.runs.run": '98',
},
function(error, response) {
console.log("response", response);
}
在这里,我收到了{ MongoError: cannot use the part (player_detail of player_detail.name) to traverse the element....
所以请帮助我如何更新满足以上三个条件的玩家run
。
提前谢谢。