MongoDB - Java

MongoDB - PHP

MongoDB - Advanced

MongoDB - Useful Resources

MongoDB - Drop Collection



In this chapter, we will see how to drop a 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.

test>show collections
mycol
myCollection
tutorialspoint
>

Now drop the collection with the name mycollection.

test>db.myCollection.drop()
true
>

Again check the list of collections into database.

test>show collections
mycol
tutorialspoint
>

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

Advertisements