Deleting a single document
No collection stays perfect forever. Sometimes, you'll need to remove outdated, invalid, or unwanted entries. MongoDB makes this easy with .delete_one(), which removes the first matching document based on a filter. In this exercise, you'll remove the movie Casablanca from the collection. It's no longer needed in our dataset. No pre-written code is available this time; you've got this!
Cet exercice fait partie du cours
Introduction to MongoDB in Python
Instructions
- Delete the movie titled
"casablanca"from the movies collection; make sure to use lower case. - Do a printout to verify that, indeed, one document got deleted.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
from pymongo import MongoClient
client = MongoClient()
mov = client.film.movies
# Delete the movie titled "casablanca"
res = ____
# Do a printout to verify the deletion
print(____)