在本章中,我們將看到如何使用MongoDB命令刪除數(shù)據(jù)庫。
db.dropDatabase()命令用于刪除 MongoDB 現(xiàn)有數(shù)據(jù)庫。
dropDatabase()命令的基本語法如下-
db.dropDatabase()
這將刪除所選的數(shù)據(jù)庫。如果您尚未選擇任何數(shù)據(jù)庫,則它將刪除默認(rèn)的“test”數(shù)據(jù)庫。
首先,使用命令 show dbs 檢查可用數(shù)據(jù)庫的列表 。
>show dbs local 0.78125GB mydb 0.23012GB test 0.23012GB >
如果要刪除新數(shù)據(jù)庫<mydb>,則使用 dropDatabase()命令如下:
>use mydb switched to db mydb >db.dropDatabase() >{ "dropped" : "mydb", "ok" : 1 } >
現(xiàn)在檢查數(shù)據(jù)庫列表。
>show dbs local 0.78125GB test 0.23012GB >