開始使用免費開始

$exists 運算子

先花點時間執行 list(mov.find()):你會發現有些電影包含 box_office 欄位,但有些沒有。讓我們更具體地了解目前的狀況。

本練習屬於課程

Python 中的 MongoDB 入門

檢視課程

練習說明

  • 找出所有包含 box_office 欄位的文件,並將回傳的 cursor 物件存成 box_curs
  • 將該 cursor 物件轉成 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.")
編輯並執行程式碼