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 :
db.collection.drop()
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 :
- First, check all the collections available.
show collections
- Drop a collection using :
db.collection.drop()
- Check the collections again. It should show the latest collections.
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.