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


当前回答

下面是一些使用mongodb完全删除操作的mongo shell

删除集合中的特定文档。删除({name:"stack"})

删除集合中的所有文档:db.mycollection.remove()

删除集合:db.mycollection.drop()

删除数据库。 首先使用mydb命令进入该数据库,然后

db.dropDatabase()

mydb——eval "db.dropDatabase() "

其他回答

最好的方法是从mongodb控制台执行:

> use mydb; 
> db.dropDatabase();

或者,您可以停止mongod并从数据目录中删除数据文件,然后重新启动。

提示:您还可以将数据文件移动到子文件夹中,如果您确定不再需要它们,可以删除它们。

其他方式:

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

我发现这很容易记住:

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完全删除操作的mongo shell

删除集合中的特定文档。删除({name:"stack"})

删除集合中的所有文档:db.mycollection.remove()

删除集合:db.mycollection.drop()

删除数据库。 首先使用mydb命令进入该数据库,然后

db.dropDatabase()

mydb——eval "db.dropDatabase() "

是这样的:

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

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