In this section, we show you how to use MongoDB to delete collections.
Used in MongoDB drop() Method to delete the collection.
语法格式:
db.collection.drop()
Parameter description:
None
返回值
If the selected collection is successfully deleted, the In the database mydb, we can first view the existing collections through the show collections command: Then delete the collection View the database again through show collections It can be seen from the results drop() Method returns true Otherwise, return false . 3.12.1. Example ¶
>use mydb
switched to db mydb
>show collections
mycol
mycol2
system.indexes
runoob
>
mycol2 :>db.mycol2.drop()
true
>
mydb Collections in:>show collections
mycol
system.indexes
runoob
>
mycol2 The collection has been deleted.