@ Override public synchronized Mongo connect ( ) { if ( m == null ) { final String dbName = mongoClientURI . getDatabase ( ) ; if ( isNullOrEmpty ( dbName ) ) { LOG . error ( "The MongoDB database name must not be null or empty (mongodb_uri was: {})" , mongoClientURI ) ; throw new RuntimeException ( "MongoDB database name is missing." ) ; } m = new MongoClient ( mongoClientURI ) ; db = m . getDB ( dbName ) ; db . setWriteConcern ( WriteConcern . ACKNOWLEDGED ) ; mongoDatabase = m . getDatabase ( dbName ) . withWriteConcern ( WriteConcern . ACKNOWLEDGED ) ; } try { db . command ( "{ ping: 1 }" ) ; } catch ( MongoCommandException e ) { if ( e . getCode ( ) == 18 ) { throw new MongoException ( "Couldn't connect to MongoDB. Please check the authentication credentials." , e ) ; } else { throw new MongoException ( "Couldn't connect to MongoDB: " + e . getMessage ( ) , e ) ; } } final Version mongoVersion = getMongoVersion ( m . getDB ( "admin" ) ) ; if ( mongoVersion != null && mongoVersion . lessThan ( MINIMUM_MONGODB_VERSION ) ) { LOG . warn ( "You're running MongoDB {} but Graylog requires at least MongoDB {}. Please upgrade." , mongoVersion , MINIMUM_MONGODB_VERSION ) ; } return m ; }
Connect the instance .