Docs Menu

Delete Data from MongoDB

In this guide, you will delete data from MongoDB.

Time required: 10 minutes

1
2

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

3

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

4

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

5

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:

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
CRUD
  • 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

Select your language

Give Feedback
© 2022 MongoDB, Inc.

About

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