1

I'm getting started with MongoDB in Java, and I'm trying to print my databases. I'm using the following code and .getDatabaseNames() is deprecated, is there a better way to do this? Or it doesn't matter? It is working fine. Thanks in advance.

private static void printDatabases(MongoClient mongo) {
    List<String> dbs = mongo.getDatabaseNames();
    for (String db : dbs) {
        System.out.println(" - " + db);
    }
}
qapt
  • 101
  • 2
  • 12

1 Answers1

2

You are looking for listDatabases()

Faraz
  • 6,025
  • 5
  • 31
  • 88