CommencerCommencer gratuitement

Updating a single document

It looks like there's an error in the database entry for The Revenant.

The release year is incorrect, and it's missing its Oscar win. You can see these errors by running this code in the shell:

mov.find_one({ "title": "the revenant" })

Let's fix this!

⚠️ Heads up! The exercises in this chapter modify the database. If you run the same code multiple times, you may see different results. Refresh the web page in your browser if you want to start with a clean slate.

Cet exercice fait partie du cours

Introduction to MongoDB in Python

Afficher le cours

Instructions

  • Define the query_filter to match the movie "the revenant" (use this casing).
  • Complete the definition of update to set "won_oscar" to True and "release_year" to 2015.
  • Perform the actual update, using query_filter and update.
  • Print out how many documents were modified.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Define the title filter
query_filter = {
  ____: ____
}

# Define the update dictionary
update = {
  ____: {
    ____: ____,
    ____: ____
  }
}

# Perform the update
res = mov.____

# How many records were modified?
print(____)
Modifier et exécuter le code