Delete Documents
On this page
You can delete documents in MongoDB using the following methods:
Your programming language's driver.
The MongoDB Atlas UI. To learn more, see Delete a Document with MongoDB Atlas.
➤ Use the Select your language drop-down menu in the upper-right to set the language of the following examples or select MongoDB Compass.
Delete All Documents
Delete All Documents that Match a Condition
Delete Only One Document that Matches a Condition
Delete a Document with MongoDB Atlas
Note
You can delete only one document at a time in the MongoDB Atlas UI.
To delete multiple documents, connect to your
Atlas deployment from mongosh
or a MongoDB driver
and follow the examples on this page for your preferred method.
The example in this section uses the sample movies dataset. To learn how to load the sample dataset into your MongoDB Atlas deployment, see Load Sample Data.
To delete a document in MongoDB Atlas, follow these steps:
Specify a query filter document.
Optionally, you can specify a query filter document in the Filter field. A query filter document uses query operators to specify search conditions.
Copy the following query filter document into the Filter search bar and click Apply:
{ genres: "Action", rated: { $in: [ "PG", "PG-13" ] } }
This query filter returns all documents in the sample_mflix.movies
collection where genres
equals Action
and rated
equals either
PG
or PG-13
.
To learn more, see Create, View, Update, and Delete Documents.
Delete Behavior
Indexes
Delete operations do not drop indexes, even if deleting all documents from a collection.
Atomicity
All write operations in MongoDB are atomic on the level of a single document. For more information on MongoDB and atomicity, see Atomicity and Transactions.
Write Acknowledgement
With write concerns, you can specify the level of acknowledgement requested from MongoDB for write operations. For details, see Write Concern.