Get startedGet started for free

We've got options

Sometimes, we wish to find documents where a field's value matches any of a set of options. We saw that the $in query operator can be used for this purpose. For example, how many laureates were born in any of "Canada", "Mexico", or "USA"?

If we wish to accept all but one option as a value for a field, we can use the $ne (not equal) operator. For example, how many laureates died in the USA but were not born in the USA?

This exercise is part of the course

Introduction to MongoDB in Python

View Course

Hands-on interactive exercise

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

# Save a filter for laureates born in the USA, Canada, or Mexico
criteria = { ____: 
                { "$in": ____}
             }

# Count them and save the count
count = db.____.____(____)
print(count)
Edit and Run Code