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


当前回答

为了确保你放弃了正确的数据库使用

mongo <connection properties> --eval "db.getSiblingDB('dbname').dropDatabase()" 

在尝试保存到mongodb时,请参阅身份验证失败以了解问题。

其他回答

我发现这很容易记住:

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 }

你不需要heredocs或eval, mongo本身就可以充当解释器。

#!/usr/bin/env mongo
var db = new Mongo().getDB("someDatabase");
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.

打开终端,输入:

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

数据库删除命令为:

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

use < database name >

2. 然后用这个。。

db.dropDatabase()