Home >>MongoDB Tutorial >MongoDB Drop Collection

MongoDB Drop Collection

How to Drop Collection using MongoDB

The drop() Method

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

Syntax

Basic syntax of drop() command is as follows −

db.COLLECTION_NAME.drop()

Example

First, check the available collections into your database mydb.

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

Now drop the collection with the name mycollection.

>db.mycollection.drop()
true
>

Again check the list of collections into database.

>show collections
mycol
system.indexes
phptpoint
>

The drop() method returns true if it successfully dropped the selected collection, otherwise it returns false.


No Sidebar ads