How do I drop a MongoDB database from the command line?
从我的bash提示符下执行此操作的最简单方法是什么?
Like this:
mongo <dbname> --eval "db.dropDatabase()"
More info on scripting the shell from the command line here: https://docs.mongodb.com/manual/tutorial/write-scripts-for-the-mongo-shell/#scripting
The best way to do it is from the mongodb console:
> use mydb; 
> db.dropDatabase();
 Alternatively, you can stop mongod and delete the data files from your data directory, then restart.  
Hint: you can also move the data files to a subfolder, and delete them if you're sure you no longer need them.
 You don't need heredocs or eval , mongo itself can act as an interpreter.  
#!/usr/bin/env mongo
var db = new Mongo().getDB("someDatabase");
db.dropDatabase();
Make the file executable and run it.
链接地址: http://www.djcxy.com/p/49684.html下一篇: 如何从命令行删除MongoDB数据库?
