How to drop a collection in MongoDB

Introduction :

Dropping a collection will remove it from the database. It will also remove any index associated with the dropped collection. It also removes all indexes associated with the dropped collection. This method will obtain a write lock on the database. It will block all other operations till the drop is completed.

Collection drop example :

The syntax of the drop method is as below :


is a document that was introduced in MongoDB 4.0. This is an optional parameter and it takes one boolean value writeConcern . It is used for setting write concern for the drop operation. drop() returns either true or false. If the collection drop is successfull , it will return true, else false. Let me show you with an example how it works :

  1. First, check all the collections available.
show collections
  1. Drop a collection using :
  1. Check the collections again. It should show the latest collections.

mongodb drop collection

Conclusion :

We have learnt how to drop a collection in MongoDB. Try the above example on your side and drop one comment below if you have any concern.