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://codercto.com/courses/l/32.html

查看所有标签

iGen

iGen

Jean M. Twenge PhD / Atria Books / 2017-8-22 / USD 27.00

A highly readable and entertaining first look at how today’s members of iGen—the children, teens, and young adults born in the mid-1990s and later—are vastly different from their Millennial predecesso......一起来看看 《iGen》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

SHA 加密
SHA 加密

SHA 加密工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具