替换整个文档
您影片集合中的《Aladdin》条目已过时。现在需要将其完整替换为 2019 年上映的新版信息。为此,您将使用 .replace_one(),它会用新文档替换整个旧文档。
本练习是课程的一部分
Python 中的 MongoDB 入门
练习说明
- 创建
query_filter,按标题匹配原版《Aladdin》电影。 - 完成
aladdin_new的定义,将"release_year"设为2019。 - 用新文档覆盖旧文档。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Specify the query_filter
query_filter = {
____: ____
}
# Complete the details of the new movie
aladdin_new = {
"title": "aladdin",
"genre": ["adventure", "comedy", "family"],
"____": ____,
"rating": 6.9
}
# Replace the old aladdin movie
res = ____
print(res)