Get startedGet started for free

Organizations and prizes over time

How many organizations won prizes before 1945 versus in or after 1945?

This exercise is part of the course

Introduction to MongoDB in Python

View Course

Exercise instructions

  • You won't need the $elemMatch operator at all for this exercise.
  • Save a filter before to count organization laureates with prizes won before 1945. Recall that organization status is encoded with the "gender" field, and that dot notation is needed to access a laureate's "year" field within its "prizes" array.
  • Save a filter in_or_after to count organization laureates with prizes won in or after 1945.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Save a filter for organization laureates with prizes won before 1945
before = {
    ____: ____,
    ____: {____: "1945"},
    }

# Save a filter for organization laureates with prizes won in or after 1945
in_or_after = {
    ____: ____,
    ____: {____: "1945"},
    }

n_before = db.laureates.count_documents(before)
n_in_or_after = db.laureates.count_documents(in_or_after)
ratio = n_in_or_after / (n_in_or_after + n_before)
print(ratio)
Edit and Run Code