Bring it all together
You're building a "highlight reel" for a film app that showcases a few top-rated movies. Your goal is to retrieve the top 5 highest-rated movies released after the year 2000, but you only need to display the title and rating; nothing else!
To do this, you'll combine practically everything you've learned in this chapter; good luck! The mov
collection is still available for you to use.
Diese Übung ist Teil des Kurses
Introduction to MongoDB in Python
Anleitung zur Übung
- Fill in the filter so you only retain movies that have a
release_year
after 2000 (use$gt
). - Use projection to include only
"title"
and"rating"
(and exclude"_id"
). - Sort by
"rating"
in descending order and limit the results to the top five.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
top_rated = mov.find(
# Filter for movies released after 2000
____,
# Project only the title and rating (not id)
____
# Sort by rating descending and limit to five results
).sort("____", ____).limit(____)
print(list(top_rated))