从bash提示符中最简单的方法是什么?
当前回答
打开另一个终端窗口,执行以下命令,
mongodb
use mydb
db.dropDatabase()
该操作的输出如下所示
MAC:FOLDER USER$ mongodb
> show databases
local 0.78125GB
mydb 0.23012GB
test 0.23012GB
> use mydb
switched to db mydb
>db.dropDatabase()
{ "dropped" : "mydb", "ok" : 1 }
>
请注意,mydb仍在使用中,因此此时插入任何输入都将重新初始化数据库。
其他回答
其他方式:
echo "db.dropDatabase()" | mongo <database name>
很惊讶我们没有看到这种变化。这样可以最小化命令行上的额外参数,并显式地显示DB被切换到FOO,然后被删除:
$ mongo --host "mongodb://machine:port" --eval 'db.getSiblingDB("FOO").dropDatabase();'
在命令提示符中,首先使用以下命令连接mongodb:
mongo -h [host-name]:[port:number] -d [dbname] -u [username] -p [password]
您将使用<dbname>访问db。
运行如下命令删除整个数据库:
db.dropDatabase()
我发现这很容易记住:
mongo //to start the mongodb shell
show dbs //to list existing databases
use <dbname> //the <dbname> is the database you'd like to drop
db //should show <dbname> just to be sure I'm working with the right database
db.dropDatabase() //will delete the database & return { "dropped" : "<dbname>", "ok" : 1 }
打开终端,输入:
mongo
下面的命令应该显示列出的数据库:
show dbs
/* the <dbname> is the database you'd like to drop */
use <dbname>
/* the below command will delete the database */
db.dropDatabase()
终端输出如下:
{
"dropped": "<dbname>",
"ok": 1
}
推荐文章
- 如何排序mongodb与pymongo
- 如何在mongodb上导入。bson文件格式
- JSON文件的蒙古导入
- 如何删除mongodb中的数组元素?
- 修改MongoDB数据存储目录
- 在MongoDB中查找重复的记录
- 为什么MongoDB Java驱动在条件中使用随机数生成器?
- 在猫鼬,我如何排序的日期?(node . js)
- 将映像存储在MongoDB数据库中
- 重复Mongo ObjectId的可能性在两个不同的集合中生成?
- Redis比mongoDB快多少?
- 无法连接到服务器127.0.0.1:27017
- 如何创建数据库的MongoDB转储?
- 如何将MongoDB作为Windows服务运行?
- 如何监听MongoDB集合的变化?