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


当前回答

打开终端,输入:

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
}

其他回答

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

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

db将显示当前的数据库名称 类型:db.dropDatabase ();

1-使用'use'关键字选择要删除的数据库。

2-然后输入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 }

其他方式:

echo "db.dropDatabase()" | mongo <database name>

尽管有几种方法,但最好的(最有效和最简单的)方法是使用db.dropDatabase()