我的猫鼬结构如下:
{
"_id": "5ea1a61c68b82c3a844e0a36",
"decks": [
{
"cards": [
{
"_id": "5ea1a61c68b82c3a844e0a38",
"countryname": "France",
"language": "French"
},
{
"_id": "5ea1a61c68b82c3a844e0a39",
"countryname": "Mexico",
"language": "Spanish"
}
],
"_id": "5ea1a61c68b82c3a844e0a37",
"name": "Countries"
}
]
"__v": 0
}
让我说我想删除法国卡,我该怎么做?香港专业教育学院看了很多例子,但我似乎无法弄清楚。 这是我现在的猫鼬查询:
Decks.update({'_id': req.body.globalid},{$pull: {'decks.cards': {'_id': req.params.cardid}}}, function(err) {
})
提前谢谢
更新!:
我终于明白了,解决方法:
Decks.update({"_id": req.body.globalid, "decks._id": req.params.deckid},{$pull: {"decks.$.cards": {"_id": req.params.cardid}}}, function(err) {
})