/** * @return all configured databases */ @Override public Iterable<MongoDatabase> getDatabases() { return () -> clients.entrySet().stream().map(e -> { MongoDBConnectionConfig c = getDescriptor(XP_CONNECTION, e.getKey()); return MongoDBConnectionHelper.getDatabase(e.getValue(), c.dbname); }).iterator(); }
/** * @param id the connection id to retrieve. * @return the database configured by {@link MongoDBConnectionConfig} for the input id, or the default one if it * doesn't exist */ @Override public MongoDatabase getDatabase(String id) { MongoDBConnectionConfig config = getDescriptor(XP_CONNECTION, id); MongoClient client = clients.get(id); if (client == null) { config = getDescriptor(XP_CONNECTION, DEFAULT_CONNECTION_ID); client = clients.get(DEFAULT_CONNECTION_ID); } return MongoDBConnectionHelper.getDatabase(client, config.dbname); }