How to drop a collection in MongoDB
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 https://docs.mongodb.com/manual/reference/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.
2. Drop a collection using :
3. Check the collections again. It should show the latest collections.
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.