/** * Attempts to find an existing MongoClient instance matching that URI in the holder, and returns it if exists. Otherwise creates a * new Mongo instance based on this URI and adds it to the holder. * * @param uri the Mongo URI * @return the client * @throws MongoException if there's a failure * @deprecated Please use {@link #connect(MongoClientURI)} instead. */ @SuppressWarnings("deprecation") @Deprecated public Mongo connect(final MongoURI uri) { return connect(uri.toClientURI()); }
/** * Attempts to find an existing MongoClient instance matching that URI in the holder, and returns it if exists. Otherwise creates a * new Mongo instance based on this URI and adds it to the holder. * * @param uri the Mongo URI * @return the client * @throws MongoException if there's a failure * @deprecated Please use {@link #connect(MongoClientURI)} instead. */ @SuppressWarnings("deprecation") @Deprecated public Mongo connect(final MongoURI uri) { return connect(uri.toClientURI()); }
public static DBCollection getCollection( MongoURI uri ){ try { Mongo mongo = _mongos.connect( uri ); DB myDb = mongo.getDB(uri.getDatabase()); //if there's a username and password if(uri.getUsername() != null && uri.getPassword() != null && !myDb.isAuthenticated()) { boolean auth = myDb.authenticate(uri.getUsername(), uri.getPassword()); if(auth) { log.info("Sucessfully authenticated with collection."); } else { throw new IllegalArgumentException( "Unable to connect to collection." ); } } return uri.connectCollection(mongo); } catch ( final Exception e ) { throw new IllegalArgumentException( "Unable to connect to collection." + e.getMessage(), e ); } }
try { final MongoClientURI uri = new MongoClientURI(dbUrl); mongoClient = (MongoClient) Mongo.Holder.singleton().connect(uri); db = mongoClient.getDB(uri.getDatabase()); } catch (final Exception e) {
public static DBCollection getCollection( MongoURI uri ){ try { Mongo mongo = _mongos.connect( uri ); DB myDb = mongo.getDB(uri.getDatabase()); //if there's a username and password if(uri.getUsername() != null && uri.getPassword() != null && !myDb.isAuthenticated()) { boolean auth = myDb.authenticate(uri.getUsername(), uri.getPassword()); if(auth) { log.info("Sucessfully authenticated with collection."); } else { throw new IllegalArgumentException( "Unable to connect to collection." ); } } return uri.connectCollection(mongo); } catch ( final Exception e ) { throw new IllegalArgumentException( "Unable to connect to collection." + e.getMessage(), e ); } }
public static DBCollection getCollection( MongoURI uri ){ try { Mongo mongo = _mongos.connect( uri ); DB myDb = mongo.getDB(uri.getDatabase()); //if there's a username and password if(uri.getUsername() != null && uri.getPassword() != null && !myDb.isAuthenticated()) { boolean auth = myDb.authenticate(uri.getUsername(), uri.getPassword()); if(auth) { log.info("Sucessfully authenticated with collection."); } else { throw new IllegalArgumentException( "Unable to connect to collection." ); } } return uri.connectCollection(mongo); } catch ( final Exception e ) { throw new IllegalArgumentException( "Unable to connect to collection." + e.getMessage(), e ); } }
public static DBCollection getCollection( MongoURI uri ){ try { Mongo mongo = _mongos.connect( uri ); DB myDb = mongo.getDB(uri.getDatabase()); //if there's a username and password if(uri.getUsername() != null && uri.getPassword() != null && !myDb.isAuthenticated()) { boolean auth = myDb.authenticate(uri.getUsername(), uri.getPassword()); if(auth) { log.info("Sucessfully authenticated with collection."); } else { throw new IllegalArgumentException( "Unable to connect to collection." ); } } return uri.connectCollection(mongo); } catch ( final Exception e ) { throw new IllegalArgumentException( "Unable to connect to collection." + e.getMessage(), e ); } }
public static DBCollection getCollection( MongoURI uri ){ try { Mongo mongo = _mongos.connect( uri ); DB myDb = mongo.getDB(uri.getDatabase()); //if there's a username and password if(uri.getUsername() != null && uri.getPassword() != null && !myDb.isAuthenticated()) { boolean auth = myDb.authenticate(uri.getUsername(), uri.getPassword()); if(auth) { log.info("Sucessfully authenticated with collection."); } else { throw new IllegalArgumentException( "Unable to connect to collection." ); } } return uri.connectCollection(mongo); } catch ( final Exception e ) { throw new IllegalArgumentException( "Unable to connect to collection." + e.getMessage(), e ); } }