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


当前回答

一行远程删除mongo数据库中的所有集合

注意必须使用——host, (-h为mongo命令的help), -d无选项,password后选择db和command。

mongo --host <mongo_host>:<mongo_port> -u <db_user> -p <db_pass> <your_db> --eval "db.dropDatabase()"

其他回答

启动MongoDB

数据库删除命令为:

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

use < database name >

2. 然后用这个。。

db.dropDatabase()

是这样的:

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

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

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

use <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 }

打开终端,输入:

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
}