MongoDB 删除数据库的语法格式如下:
db.dropDatabase()
删除当前数据库,默认为 test,你可以使用 db 命令查看当前数据库名。
以下实例我们删除了数据库 itzixishi。
首先,查看所有数据库:
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
itzixishi 0.000GB
接下来我们切换到数据库 itzixishi:
> use itzixishi
switched to db itzixishi
>
执行删除命令:
> db.dropDatabase()
{ "dropped" : "itzixishi", "ok" : 1 }
最后,我们再通过 show dbs 命令数据库是否删除成功:
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
集合删除语法格式如下:
db.collection.drop()
以下实例删除了 itzixishi 数据库中的集合 site:
> use itzixishi
switched to db itzixishi
> db.createCollection("itzixishi") # 先创建集合,类似数据库中的表
> show tables # show collections 命令会更加准确点
itzixishi
> db.itzixishi.drop()
true
> show tables
>
©2020 IT自习室京ICP备20010815号