MongoDB 删除集合

drop()方法

db.collection.drop()用于从MongoDB数据库删除集合。

语法

drop()命令的基本语法如下-

db.COLLECTION_NAME.drop()

示例

首先,将可用的集合检入数据库mydb。

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

现在删除名称为 mycollection 的集合。

>db.mycollection.drop()
true
>

再次检查收集到数据库的列表。

>show collections
mycol
system.indexes
sfjvip
>

如果成功删除选定的集合,则drop()方法将返回true,否则将返回false。

编程笔记 » MongoDB 删除集合