icon-cookie
The website uses cookies to optimize your user experience. Using this website grants us the permission to collect certain information essential to the provision of our services to you, but you may change the cookie settings within your browser any time you wish. Learn more
I agree
blank_error__heading
blank_error__body
Text direction?

MongoDB 删除数据库

语法

MongoDB 删除数据库的语法格式如下:

db.dropDatabase()

删除当前数据库,默认为 test,你可以使用 db 命令查看当前数据库名。

实例

以下实例我们删除了数据库 runoob。

首先,查看所有数据库:

> show dbs
local0.078GB
runoob  0.078GB
test    0.078GB

接下来我们切换到数据库 runoob:

>use runoob
switched to db runoob
>

执行删除命令:

> db.dropDatabase(){"dropped":"runoob","ok":1}

最后,我们再通过 show dbs 命令数据库是否删除成功:

> show dbs
local0.078GB
test   0.078GB>

删除集合

集合删除语法格式如下:

db.collection.drop()

以下实例删除了 runoob 数据库中的集合 site:

>use runoob
switched to db runoob
> show tables
site
> db.site.drop()true> show tables
>
Measure
Measure
Related Notes
Get a free MyMarkup account to save this article and view it later on any device.
Create account

End User License Agreement

Summary | 1 Annotations
show tables
2018/04/26 13:20