Docs Menu

Docs HomeStart with Guides

Delete Data from MongoDB

In this guide, you will delete data from MongoDB.

Time required: 10 minutes


Switch to the database and collection you wish to query. In this case you will be using the sample_guides database and comets collection.


The following example illustrates using a query filter to delete documents where their orbitalPeriod is greater than 5 and less than 85.


The result contains some information about the delete operation. To verify you deleted documents, print the amount of documents the driver deleted.


Here is the complete code followed by sample output.

If you have completed this guide, you have deleted data from MongoDB.

That completes this introduction to CRUD operations in MongoDB.

See the following resources for more in-depth information about the concepts presented here:

  • Delete Documents

  • Delete Methods

What's Next
Build a Dynamic Index
5 mins

Retrieve documents in MongoDB with full-text search.

Start Guide
Chapter 3
Atlas Search
  • Build a Dynamic Index
  • Build an Index with Static Field Mappings
  • Querying with the Compound Operator
  • Querying with Facets
Start with Guides →