`$exists` 运算符
先运行一下 list(mov.find()):您会发现有些电影包含 box_office 字段,而有些没有。让我们更清楚地了解一下这种情况。
本练习是课程的一部分
Python 中的 MongoDB 入门
练习说明
- 找到所有存在
box_office字段的文档,并将返回的游标对象保存为box_curs。 - 将该游标对象转换为 Python 列表,并将其保存为
box。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Find all documents where box_office is set
box_curs = mov.find({
"____": {
"____": ____
}
})
# Convert from cursor to list
box = ____
print(box)
print(f"{len(box)}/{mov.count_documents({})} movies have the box_office field.")