MongoDB 刪除數(shù)據(jù)庫的語法格式如下:
db.dropDatabase()
刪除當前數(shù)據(jù)庫,默認為 test,你可以使用 db 命令查看當前數(shù)據(jù)庫名。
以下實例我們刪除了數(shù)據(jù)庫 youj。
首先,查看所有數(shù)據(jù)庫:
> show dbs
local 0.078GB
youj 0.078GB
test 0.078GB
接下來我們切換到數(shù)據(jù)庫 youj:
> use youj
switched to db youj
>
執(zhí)行刪除命令:
> db.dropDatabase()
{ "dropped" : "youj", "ok" : 1 }
最后,我們再通過 show dbs 命令數(shù)據(jù)庫是否刪除成功:
> show dbs
local 0.078GB
test 0.078GB
>
集合刪除語法格式如下:
db.collection.drop()
更多建議: