Get startedGet started for free

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.

This exercise is part of the course

Introduction to MongoDB in Python

View Course

Exercise instructions

  • 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.

Hands-on interactive exercise

Have a go at this exercise by completing this sample 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))
Edit and Run Code