public void testDatabase() { MongoClient mongoClient = mongo.getClient("mongo1"); ListDatabasesIterable<Document> list = mongoClient.listDatabases(); MongoCursor<Document> iterD = list.iterator(); while (iterD.hasNext()) { Document doc = iterD.next(); System.out.println(doc); if (!doc.getBoolean("empty", true)) { System.out.println(mongoClient.getDatabase(doc .getString("name"))); } } // MongoIterable<String> mongo = mongoClient.listDatabaseNames(); // MongoCursor<String> iter = mongo.iterator(); // while (iter.hasNext()) { // System.out.println(iter.next()); // } }
public void testDatabase() { ListDatabasesIterable<Document> list = mongoClient.listDatabases(); MongoCursor<Document> iterD = list.iterator(); while (iterD.hasNext()) { Document doc = iterD.next(); System.out.println(doc); if (!doc.getBoolean("empty", true)) { System.out.println(mongoClient.getDatabase(doc .getString("name"))); } } // MongoIterable<String> mongo = mongoClient.listDatabaseNames(); // MongoCursor<String> iter = mongo.iterator(); // while (iter.hasNext()) { // System.out.println(iter.next()); // } }
public ListDatabasesIterable<Document> listDatabases() { return mongoClient.listDatabases(); }
/** * Gets the list of databases * * @return the list of databases */ public ListDatabasesIterable<Document> listDatabases() { return listDatabases(Document.class); }
/** * Gets the list of databases * * @param clazz * the class to cast the database documents to * @param <T> * the type of the class to use instead of {@code Document}. * @return the list of databases */ public <T> ListDatabasesIterable<T> listDatabases(final Class<T> clazz) { return client.listDatabases(clazz); }