检查mongodb数据库是否存在? [英] Check if mongodb database exists?

查看:513
本文介绍了检查mongodb数据库是否存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有可能检查一个mongo数据库是否已经存在?

Is there a possibility to check if a mongo database allready exists?

推荐答案

数据库。从Java驱动程序,你可以这样做,以获取在localhost上运行的 mongod 服务器上的数据库名称

Yes, you can get the list of existing databases. From the Java driver you could do something like this to get the database names on a mongod server running on localhost

Mongo mongo = new Mongo( "127.0.0.1", 27017 );
List<String> databaseNames = mongo.getDatabaseNames();

这相当于mongo shell的show dbs命令。我确信所有的驱动程序都存在类似的方法。

This is equivalent to the mongo shell "show dbs" command. I am sure similar methods exist in all of the drivers.

这篇关于检查mongodb数据库是否存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆