MongoDB 删除数据库

MongoDB 教程 · 2019-03-05 20:26:54

语法

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

db.dropDatabase()

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

实例

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

首先,查看所有数据库:

> show dbs
local   0.078GB
codercto  0.078GB
test    0.078GB

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

> use codercto
switched to db codercto
> 

执行删除命令:

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

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

> show dbs
local  0.078GB
test   0.078GB
> 

删除集合

集合删除语法格式如下:

db.collection.drop()

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

> use codercto
switched to db codercto
> show tables
site
> db.site.drop()
true
> show tables
> 

点击查看所有 MongoDB 教程 文章: https://www.codercto.com/courses/l/32.html

查看所有标签

Programming Amazon Web Services

Programming Amazon Web Services

James Murty / O'Reilly Media / 2008-3-25 / USD 49.99

Building on the success of its storefront and fulfillment services, Amazon now allows businesses to "rent" computing power, data storage and bandwidth on its vast network platform. This book demonstra......一起来看看 《Programming Amazon Web Services》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

URL 编码/解码
URL 编码/解码

URL 编码/解码