Easy Tutorial
❮ Mongodb Sort Mongodb Java ❯

MongoDB Drop Collection

This section introduces how to delete a collection using MongoDB.

In MongoDB, the drop() method is used to delete a collection.

Syntax:

db.collection.drop()

Parameters:

Return Value

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

Example

In the database mydb, we can first list the existing collections using the show collections command:

>use mydb
switched to db mydb
>show collections
mycol
mycol2
system.indexes
tutorialpro
>

Next, delete the collection mycol2:

>db.mycol2.drop()
true
>

List the collections in the database mydb again:

>show collections
mycol
system.indexes
tutorialpro
>

From the results, it can be seen that the mycol2 collection has been deleted.

❮ Mongodb Sort Mongodb Java ❯