ComenzarEmpieza gratis

Updating multiple documents

Sometimes, multiple documents need the same update: when correcting an error or tagging records that meet certain conditions, for example. That's where .update_many() comes in.

In this exercise, you'll use it to tag Oscar-winning movies that also have a rating above 7.0 as favorites.

Este ejercicio forma parte del curso

Introduction to MongoDB in Python

Ver curso

Instrucciones del ejercicio

  • Define query_filter so it matches all movies where "won_oscar" is equal to True, and "rating" is greater than 7.0.
  • Define update to $set a new field "is_favorite" to True.
  • Perform the update for all documents that match query_filter.
  • Print out how many documents were affected by this update.

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

# Filter for Oscar winning movies with rating greater than 7.0
query_filter = {
  "____": ____,
  "____": { "____": ____ }
}

# Update to set is_favorite to True
update = ____

# Perform update for all documents that match filter
res = ____

# How many documents were affected?
print(____)
Editar y ejecutar código