private static MongoAuthority getMongoAuthorityFromURI(final MongoURI uri) throws UnknownHostException { if (uri.getHosts().size() == 1) { return MongoAuthority.direct(new ServerAddress(uri.getHosts().get(0)), uri.getCredentials()); } else { List<ServerAddress> replicaSetSeeds = new ArrayList<ServerAddress>(uri.getHosts().size()); for (String host : uri.getHosts()) replicaSetSeeds.add(new ServerAddress(host)); return MongoAuthority.dynamicSet(replicaSetSeeds, uri.getCredentials()); } }
/** * Creates a Mongo based on a list of replica set members or a list of mongos. It will find all * members (the master will be used by default). If you pass in a single server in the list, the * driver will still function as if it is a replica set. If you have a standalone server, use the * Mongo(ServerAddress) constructor. * * <p>If this is a list of mongos servers, it will pick the closest (lowest ping time) one to send * all requests to, and automatically fail over to the next server if the closest is down. * * @see com.mongodb.ServerAddress * @param seeds Put as many servers as you can in the list and the system will figure out the * rest. This can either be a list of mongod servers in the same replica set or a list of * mongos servers in the same sharded cluster. * @param options for configuring this Mongo instance * @throws MongoException * @deprecated Replaced by {@link MongoClient#MongoClient(java.util.List, MongoClientOptions)} */ @Deprecated public Mongo(List<ServerAddress> seeds, MongoOptions options) { this(MongoAuthority.dynamicSet(seeds), options); }
/** * Creates a Mongo connection in paired mode. <br> * This will also work for a replica set and will find all members (the master will be used by * default). * * @see com.mongodb.ServerAddress * @param left left side of the pair * @param right right side of the pair * @param options the optional settings for the Mongo instance * @throws MongoException * @deprecated Please use {@link MongoClient#MongoClient(java.util.List, MongoClientOptions)} * instead. */ @Deprecated public Mongo(ServerAddress left, ServerAddress right, MongoOptions options) { this(MongoAuthority.dynamicSet(Arrays.asList(left, right)), options); }