$or 運算子
你想建立一個高品質電影的清單,並為你的挑選設計條件:電影必須曾獲得美國影藝學院獎(也稱為奧斯卡),或評分高於 7.5。除了使用 $or 運算子之外,你還需要 $gte 運算子,意思是「大於或等於」(greater than or equal to)。
本練習屬於課程
Python 中的 MongoDB 入門
練習說明
- 完成
"won_oscar"上的oscar篩選,以符合第一個條件。 - 完成
"rating"上的high_rating篩選,以符合第二個條件。使用"$gte"。 - 使用
$or結合兩個條件,找出符合任一或同時符合兩個條件的所有電影。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create the won_oscar filter
oscar = { "____": ____ }
# Create the rating filter
high_rating = { "____": { "____": ____ }}
# Combine with $or
hq_curs = mov.find({
"____": [
____,
____
]
})
# Convert from cursor to list
hq = list(hq_curs)
print(hq)