MongoDB
 sql >> Base de Dados >  >> NoSQL >> MongoDB

MongoDB:verifique a conexão com o banco de dados


Eu uso isso:
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;
}