How to delete document in MongoDB
AuthorTekslate
Ratings
Views0
  • Share this blog :

Remove Documents

In MongoDB, the db.collection.remove() method removes documents from a collection. You can remove all documents from a collection, remove all documents that match a condition, or limit the operation to remove just a single document.

This tutorial provides examples of remove operations using the db.collection.remove() method in the mongo shell.

Remove All Documents

To remove all documents from a collection, pass an empty query document {} to the remove() method. The remove() method does not remove the indexes.

The following example removes all documents from the inventory collection:

Screenshot_44

Remove Documents that Match a Condition

To remove the documents that match a deletion criteria, call the remove()method with the <query>parameter.

Aspired to become an Mongo DB Training?
Explore the post to discover the know-hows on Mongo DB.

The following example removes all documents from the inventory collection where the type field equalsfood:

Screenshot_45

For large deletion operations, it may be more efficient to copy the documents that you want to keep to a new collection and then use drop()on the original collection.

Remove a Single Document that Matches a Condition

To remove a single document, call the remove() method with the justOne parameter set to true or 1.

The following example removes one document from the inventory collection where the type field equalsfood:

Screenshot_47

To delete a single document sorted by some specified order, use the find and modify method.

For indepth understanding click on

You liked the article?

Like : 228

Vote for difficulty

Current difficulty :

Previous

Stack Class in Java

Next

Stack Class in Java

Recommended Articles

Page :

How to define Variables in Development Environment - Blue Prism
Views500
Blue Prism RealWorld UseCases
Views500
Blue Prism Deployment in productions
Views500
How companies are using Blue Prism for their Business
Views500
How companies are using Blue Prism for their Business
Views500
What is Blue Prism?
Views500

Recommended Programs
logoforcourse
How to define Variables in Development Environment - Blue Prism
4.5
25695 Learners
logoforcourse
Blue Prism RealWorld UseCases
4.5
25695 Learners

1/15

About Author
Name

TekSlate

Author Bio

TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills .

TABLE OF CONTENT


What is Blue Prism?
Difference between Blue Prism and UiPath
Blue Prism Benefits
Blue Prism Projects
Blue Prism Deployment in productions
How to define Variables in Development Environment - Blue Prism
Blue Prism Benefits and Uses in RealTime
Blue Prism RealWorld UseCases
Blue Prism RealWorld UseCases
Learn more about Blue Prism

Stay Updated


Get stories of change makers and innovators from the startup ecosystem in your inbox

Related Blogs

Blue Prism Benefits and Uses in RealTime

Blue Prism RealWorld UseCases

How companies are using Blue Prism for their Business

Latest Updates in Blue Prism