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


当前回答

在命令提示符中,首先使用以下命令连接mongodb:

mongo -h [host-name]:[port:number] -d [dbname] -u [username] -p [password]

您将使用<dbname>访问db。

运行如下命令删除整个数据库:

db.dropDatabase()

其他回答

从mongo shell中使用以下命令删除db

use <database name>; 
db.dropDatabase();

打开另一个终端窗口,执行以下命令,

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仍在使用中,因此此时插入任何输入都将重新初始化数据库。

在终端执行:

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命令行: 并键入下面的命令。 使用“YOUR_DATABASE_NAME”; 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 }