【发布时间】:2018-01-09 07:05:21
【问题描述】:
我已经在连接字符串中指定了要连接的数据库,所以我希望我可以在没有硬编码的情况下获得数据库实例。
但是 mongoDbClient.getDatabase 方法需要数据库名称作为参数。有什么简单的方法吗?
MongoClient mongoClient = new MongoClientURI(DispatcherConfigHolder.config.getMongoUrl());//I will put the uri in a config file so that I can change the db easily
MongoDatabase db = ...//need a MongoDataBase here
MongoCollection collection = db.getCollection("device");//so that I can access the collection from it
【问题讨论】: