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.
Cet exercice fait partie du cours
Introduction to MongoDB in Python
Instructions
- Fill in the filter so you only retain movies that have a
release_yearafter 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.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
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))