From the course: MongoDB Python Developer Associate Cert Prep

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Deleting documents in Python applications

Deleting documents in Python applications

- Hello. In this video, you'll learn how to use the delete_one() and delete_many() methods to delete documents in MongoDB by using the PyMongo driver. We can delete a single document from a collection by using the delete_one() method. The delete_one() method accepts a query filter that matches a document that we want to delete. Let's go through an example. We'll work with a database named bank that contains an accounts collection. Let's say that we want to delete the document from the accounts collection that matches this _id value. It's appropriate to use delete_one() for this query because there can only be one document in a collection that matches any given _id value. We've already started a Python file and connected to our Atlas cluster with Mongo client. We have a reference to the bank database and a reference to the accounts collection. First, we create the filter that matches the _id value of the document that we…

Contents