Docs Menu

Docs HomeStart with Guides

Delete Data from MongoDB

In this guide, you will delete data from MongoDB.

Time required: 10 minutes

  • A connection string to your MongoDB deployment.

  • Sample datasets loaded into your cluster.

  • An installed MongoDB Driver.


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
Become a MongoDB Professional

Congrats. You’ve completed all the guides. Want to take the next step? Register for the developer exam.

Learn More
Chapter 2
  • Add a MongoDB Driver
  • Read Data in MongoDB
  • Read Data from MongoDB With Queries
  • Read Data using Operators and Compound Queries
  • Insert Data into MongoDB
  • Update Data in MongoDB
  • Delete Data from MongoDB
Share Feedback
© 2022 MongoDB, Inc.


  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2022 MongoDB, Inc.