1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to MongoDB in Python

Connected

Exercise

Sort it out!

Want to list movies from the oldest classic to the latest blockbuster? Or maybe highlight the top-rated films first? That's where .sort() comes in.

Use .sort(field, direction) to control the order of your query results:

  • field is the name of the field to sort by
  • direction is 1 for ascending (A-Z, low-high), -1 for descending (Z-A, high-low)

Instructions

100 XP
  • List all movies sorted by release_year (oldest to newest).
  • List the top 3 highest-rated movies, sorted by rating in descending order.