MongoDB-Drop Collection

MongoDB-Drop Collection

drop() method

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

Syntax

The basic syntax of the drop() command is as follows:

db.COLLECTION_NAME.drop()

example

First check the available collections in your mydb database .

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

Now drop a collection named mycollection .

> db . mycollection . drop () true >

Again check the list of collections in the database.

> show collections
mycol
system . indexes
tutorialspoint
>

The drop() method will return true if the selected collection has been successfully dropped, otherwise it will return false.