鍍金池/ 教程/ 數(shù)據(jù)庫/ 刪除集合
更新文檔
GridFS
Rockmongo 管理工具
Map Reduce
Java
創(chuàng)建備份
數(shù)據(jù)模型
創(chuàng)建數(shù)據(jù)庫
映射
查詢文檔
索引限制
ObjectId
刪除文檔
數(shù)據(jù)類型
高級索引
索引
優(yōu)勢
記錄排序
查詢分析
插入文檔
刪除集合
全文檢索
創(chuàng)建集合
概述
數(shù)據(jù)庫引用
覆蓋索引查詢
安裝環(huán)境
PHP
刪除數(shù)據(jù)庫
固定集合
關(guān)系
聚合
自動增長
復(fù)制
限制記錄
部署
分片
正則表達(dá)式
原子操作

刪除集合

drop() 方法

MongoDB 利用 db.collection.drop() 來刪除數(shù)據(jù)庫中的集合。

語法格式

drop() 命令的基本格式如下:

db.COLLECTION_NAME.drop()

范例

首先檢查在數(shù)據(jù)庫 mydb 中已有集合:

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

接著刪除集合 mycollection。

>db.mycollection.drop()
true
>

再次檢查數(shù)據(jù)庫中的現(xiàn)有集合:

>show collections
mycol
system.indexes
tutorialspoint
>

如果成功刪除選定集合,則 drop() 方法返回 true,否則返回 false。