ComeçarComece de graça

Gap years

The prize in economics was not added until 1969. There have also been many years for which prizes in one or more of the original categories were not awarded.

In this exercise, you will utilize sorting by multiple fields to see which categories are missing in which years.

For now, you will just print the list of all documents, but in the next chapter, you'll learn how to use MongoDB to group and aggregate data to present this information in a more convenient format.

Este exercício faz parte do curso

Introduction to MongoDB in Python

Ver curso

Instruções do exercício

  • Find the original prize categories established in 1901 by looking at the distinct values of the "category" field for prizes from year 1901.
  • Fetch ONLY the year and category from all the documents (without the "_id" field).
  • Sort by "year" in descending order, then by "category" in ascending order.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# original categories from 1901
original_categories = db.prizes.____(____, {____: ____})
print(original_categories)

# project year and category, and sort
docs = db.prizes.find(
        filter={},
        ____ = ____
        sort=[____,____]
)

#print the documents
for doc in docs:
  print(doc)
Editar e executar o código