CommencerCommencer gratuitement

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.

Cet exercice fait partie du cours

Introduction to MongoDB in Python

Afficher le cours

Instructions

  • Complete the oscar filter on "won_oscar" to reflect the first condition.
  • Complete the high_rating filter on "rating" to reflect the second condition. Use "$gte".
  • Combine the two criteria using $or to find all movies that match one or both of the criteria.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de 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)
Modifier et exécuter le code