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。