MongoDB Tutorial - MongoDB Drop Collection








MongoDB's db.collectionName.drop() is used to drop a collection from the database.

Syntax

The syntax of drop() command is as follows

db.COLLECTION_NAME.drop()

drop() method will return true, if the selected collection is dropped successfully otherwise it will return false

Example

First, check the available collections in mydb.

>use mydb
switched to db mydb
>show collections
mycol
mycollection
system.indexes
java2s
>

Drop the collection mycollection.

>db.mycollection.drop()
true
>

Check the available collections in database.

>show collections
mycol
system.indexes
java2s
>