MongoDB
 sql >> Database >  >> NoSQL >> MongoDB

MongoDB:verifica la connessione al DB

Io uso questo:

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;
}