LoslegenKostenlos loslegen

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!

Diese Übung ist Teil des Kurses

Introduction to MongoDB in Python

Kurs anzeigen

Anleitung zur Übung

  • 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.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

from pymongo import MongoClient 
client = MongoClient()
mov = client.film.movies

# Delete the movie titled "casablanca"
res = ____

# Do a printout to verify the deletion
print(____)
Code bearbeiten und ausführen