MongoDB
 sql >> Datenbank >  >> NoSQL >> MongoDB

MongoDB:Verbindung zur DB prüfen

Ich benutze das:

Builder o = MongoClientOptions.builder().connectTimeout(3000);  
MongoClient mongo = new MongoClient(new ServerAddress("192.168.0.1", 3001), o.build());    

try {
  mongo.getAddress();
} catch (Exception e) {
  System.out.println("Mongo is down");
  mongo.close();
  return;
}