Docs Menu

Docs HomeDevelop ApplicationsMongoDB Manual

Delete Documents

On this page

  • Delete All Documents
  • Delete All Documents that Match a Condition
  • Delete Only One Document that Matches a Condition
  • Delete a Document with MongoDB Atlas
  • Delete Behavior

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.

  • MongoDB Compass.


Use the Select your language drop-down menu in the upper-right to set the language of the following examples or select MongoDB Compass.


Note

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:

1
  1. In the MongoDB Atlas UI, click Database in the sidebar.

  2. For the database deployment that contains the sample data, click Browse Collections.

  3. In the left navigation pane, select the sample_mflix database.

  4. Select the movies collection.

2

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.

3
  1. For the document that you want to delete, hover over the document and click the trash icon that appears on the right-hand side.

    After clicking the delete button, MongoDB Atlas flags the document for deletion and asks for your confirmation.

  2. Click Delete to confirm your selection.

To learn more, see Create, View, Update, and Delete Documents.

Delete operations do not drop indexes, even if deleting all documents from a collection.

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.

With write concerns, you can specify the level of acknowledgement requested from MongoDB for write operations. For details, see Write Concern.

←  Update MethodsDelete Methods →