The $or operator
You want to create a list of high-quality movies and want to design criteria for your selection: the movie needs to have won an Academy Award (also known as an Oscar), or have a rating higher than 7.5. As well as the $or operator, you will need the $gte operator, short for greater than or equal to.
This exercise is part of the course
Introduction to MongoDB in Python
Exercise instructions
- Complete the
oscarfilter on"won_oscar"to reflect the first condition. - Complete the
high_ratingfilter on"rating"to reflect the second condition. Use"$gte". - Combine the two criteria using
$orto find all movies that match one or both of the criteria.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create the won_oscar filter
oscar = { "____": ____ }
# Create the rating filter
high_rating = { "____": { "____": ____ }}
# Combine with $or
hq_curs = mov.find({
"____": [
____,
____
]
})
# Convert from cursor to list
hq = list(hq_curs)
print(hq)