在本章中,我们将看到如何使用MongoDB删除集合.
drop()方法
MongoDB的 db .collection.drop()用于从数据库中删除一个集合.
语法
drop的基本语法()命令如下 :
db.COLLECTION_NAME.drop()
示例
首先,检查数据库中的可用集合 mydb .
>use mydbswitched to db mydb> show collections mycol mycollection system.indexes it1352>
现在删除名为 mycollection 的集合.
> db.mycollection.drop() true >
再次检查集合列表到数据库中.
>show collections mycol system.indexes it1352>
如果成功删除选定的集合,drop()方法将返回true,否则返回false.