MongoDB Delete documents

In MongoDB, the db.collection.remove() technique removes reports from a collection. You can removes all records from a collection, remove all reports that match a condition, or limit the operation to remove just a single document. This tutorial exercise gives samples of uproot operations utilizing the db.collection.remove() technique in the mongo shell.


db.collection_name.remove (DELETION_CRITERIA)  

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.


db.inventory.remove({})

Remove all documents that match a condition

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

						
db.inventory.remove( { type : "food" } )

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.

							
db.inventory.remove( { type : "food" }, 1 )