从bash提示符中最简单的方法是什么?
当前回答
在终端执行:
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.
其他回答
你也可以使用"heredoc":
mongo localhost/db <<EOF
db.dropDatabase()
EOF
输出结果如下:
mongo localhost/db <<EOF
db.dropDatabase()
EOF
MongoDB shell version: 2.2.2
connecting to: localhost/db
{ "dropped" : "db", "ok" : 1 }
bye
如果你想要更复杂的命令序列,我喜欢使用heredocs。
我发现这很容易记住:
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 shell中使用以下命令删除db
use <database name>;
db.dropDatabase();
一行远程删除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()"
打开终端,输入:
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
}
推荐文章
- elasticsearch vs . MongoDB用于过滤应用程序
- MongoDB记录所有查询
- MongoDB:如何找到安装的MongoDB的确切版本
- 如何使用mongoimport导入CSV文件?
- 在mongodb中存储日期/时间的最佳方法
- 如何排序mongodb与pymongo
- 如何在mongodb上导入。bson文件格式
- JSON文件的蒙古导入
- 如何删除mongodb中的数组元素?
- 修改MongoDB数据存储目录
- 在MongoDB中查找重复的记录
- 为什么MongoDB Java驱动在条件中使用随机数生成器?
- 在猫鼬,我如何排序的日期?(node . js)
- 将映像存储在MongoDB数据库中
- 重复Mongo ObjectId的可能性在两个不同的集合中生成?