MongoDB删除每个数据库 [英] MongoDB drop every database
本文介绍了MongoDB删除每个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有命令从MongoDB中删除每个数据库?
I would like to know if there're a command to drop every databases from my MongoDB?
我知道是否只想删除一个数据表,我只需要像下面的代码一样输入数据库的名称,但是我不想指定它.
I know if I want to drop only one datatable, I just need to type the name of the database like the code below but I dont want to have to specify it.
mongo DB_NAME --eval 'db.dropDatabase();'
推荐答案
您可以创建一个执行此任务的javascript循环,然后在mongoconsole中执行它.
you can create a javascript loop that do the job and then execute it in the mongoconsole.
var dbs = db.getMongo().getDBNames()
for(var i in dbs){
db = db.getMongo().getDB( dbs[i] );
print( "dropping db " + db.getName() );
db.dropDatabase();
}
将其保存到dropall.js,然后执行:
save it to dropall.js and then execute:
mongo dropall.js
这篇关于MongoDB删除每个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文