我正在尝试通过向嵌套文档添加文档列表来更新嵌套文档。 这是我的文件:
{
"_id": {
"$oid": "5dd847e92921e045f847e46b"
},
"type": "tvshow",
"name": "The Blacklist",
"overview": "Raymond \"Red\" Reddington, one of the FBI's most wanted fugitives, surrenders in person at FBI Headquarters in Washington, D.C. He claims that he and the FBI have the same interests: bringing down dangerous criminals and terrorists. In the last two decades, he's made a list of criminals and terrorists that matter the most but the FBI cannot find because it does not know they exist. Reddington calls this \"The Blacklist\". Reddington will co-operate, but insists that he will speak only to Elizabeth Keen, a rookie FBI profiler.",
"homepage": "",
"id": null,
"poster_path": "/bgbQCW4fE9b6wSOSC6Fb4FfVzsW.jpg",
"release_date": null,
"makers": [],
"producers": [],
"actors": [],
"genres": [
80,
18,
9648
],
"globalRating": null,
"ratings": [],
"seasons": [
{
"type": "season",
"name": "Season 1",
"overview": "",
"homepage": "",
"id": null,
"poster_path": "/ccrCgW1ukxgwBue9ptkpCEjXE6q.jpg",
"release_date": null,
"makers": [],
"producers": [],
"actors": [],
"genres": [],
"globalRating": null,
"ratings": [],
"number": 1,
"episodes": []
},
{
"type": "season",
"name": "Season 2",
"overview": "",
"homepage": "",
"id": null,
"poster_path": "/b7o8AOpZPWJO8nP4SK8RRZ2d0B0.jpg",
"release_date": null,
"makers": [],
"producers": [],
"actors": [],
"genres": [],
"globalRating": null,
"ratings": [],
"number": 2,
"episodes": []
}]
}
,我想在每个季节的嵌套文档的剧集键中添加一个剧集列表。 我尝试了整个赛季的每个新剧集,但只有上个赛季才满。似乎使用addToSet运算符删除了我在前几个季节中添加的前几集:
TVShow.update_one({'_id': self._mongo_id, 'seasons.number': self._number}, {'$addToSet': {'seasons.$.episodes': episode}})
有人对这个问题有想法吗? 谢谢您的帮助