In this blog post i am going to explain how to delete MongoDB document. The are few ways which are illustrated below :

If we execute remove on collection without any params then it will delete all records

db.users.remove({})	
// it will delete all documents along with users collection it will keep the indexes. Think of it as DELETE in MySQL

Drop is used to delete a collection and it’s indexes as well.

db.users.drop()
// it will delete users collection and all the indexes. Think of it as DROP TABLE in MySQL

We can also delete selective document based on condition. Following examples illustrate the same :

db.users.remove({age:'28'});	// it will only delete all documents where age is 28

We can also use other operators for deleting documents which are explained as follows :

db.users.remove({age:{$gt:'28'}});	
// it will only delete all documents where age is greater than 28

db.users.remove({age:{$lt:'28'}});	
// it will only delete all documents where age is less than 28

You can find other post in MongoDB series at this link