从bash提示符中最简单的方法是什么?


当前回答

是这样的:

mongo <dbname> --eval "db.dropDatabase()"

关于从命令行编写shell脚本的更多信息,请访问:https://docs.mongodb.com/manual/tutorial/write-scripts-for-the-mongo-shell/#scripting

其他回答

启动MongoDB

数据库删除命令为:

1. 首先选择要删除的数据库

use < database name >

2. 然后用这个。。

db.dropDatabase()

在终端执行:

mongo // To go to shell

show databases // To show all existing databases.

use <DATA_BASE> // To switch to the wanted database.

db.dropDatabase() // To remove the current database.

在命令提示符中,首先使用以下命令连接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 }

登录到mongoDB命令行: 并键入下面的命令。 使用“YOUR_DATABASE_NAME”; db.dropDatabase ();