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!
This exercise is part of the course
Introduction to MongoDB in Python
Exercise 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.
Hands-on interactive exercise
Have a go at this exercise by completing this sample 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(____)