MongoDB 刪除資料庫

2021-09-25 11:36:43 字數 667 閱讀 2034

本章介紹如何使用mongodb命令刪除資料庫。

mongodbdb.dropdatabase()命令用於刪除資料庫。

dropdatabase()命令的基本語法如下:

db.dropdatabase(

)

這將刪除當前資料庫。如果沒有選擇任何資料庫,那麼它將刪除預設的「test」資料庫。

首先,使用命令show dbs檢查可用資料庫列表。

> show dbs

admin 0.000gb

config 0.000gb

local 0.000gb

mydb 0.000gb

如果想刪除資料庫mydb,可通過如下操作:

> use mydb

switched to db mydb

> db.dropdatabase(

)

現在檢查資料庫列表。

> show dbs

admin 0.000gb

config 0.000gb

local 0.000gb

MongoDB 刪除資料庫

mongodb 刪除資料庫的語法格式如下 db dropdatabase 刪除當前資料庫,預設為 test,你可以使用 db 命令檢視當前資料庫名。以下例項我們刪除了資料庫 runoob。首先,檢視所有資料庫 show dbs local 0.078gb runoob 0.078gb test 0....

MongoDB 刪除資料庫

mongodb 刪除資料庫的語法格式如下 db.dropdatabase 刪除當前資料庫,預設為 test,你可以使用 db 命令檢視當前資料庫名。以下例項我們刪除了資料庫 runoob。首先,檢視所有資料庫 show dbs admin 0.000gb config 0.000gb local 0...

MongoDB刪除資料庫和刪除集合

一 mongodb刪除資料庫 1 mongodb 刪除資料庫的語法格式如下 db.dropdatabase 刪除當前資料庫,預設為 test,你可以使用 db 命令檢視當前資料庫名。2 例項 以下例項我們刪除了資料庫 students。首先,檢視所有資料庫 show dbs local 0.000g...