MongoDB Delete Collection
In this chapter we introduce how to use MongoDB to delete collections.
In MongoDB, use the drop() method to delete a collection.
The drop() method can permanently delete a specified collection and all its documents from the database. This is an irreversible operation, so it should be used with caution.
Syntax format:
db.collection.drop()
Parameter Description:
- None
Return Value
If the selected collection is successfully deleted, the drop() method returns true, otherwise it returns false.
Example
In the database mydb, we can first view existing collections through the show collections command:
>use mydb
switched to db mydb
>show collections
mycol
mycol2
system.indexes
runoob
>
Then delete the collection mycol2:
>db.mycol2.drop()
true
>
View the collections in the database mydb again through show collections:
>show collections
mycol
system.indexes
runoob
>
From the result, we can see that the mycol2 collection has been deleted.