Mongo mongo;
if(host.contains(",")) {
String[] hosts = host.split(",");
List<ServerAddress> addresses = new ArrayList<ServerAddress>();
for (String hostUrl : hosts) {
ServerAddress serverAddress;
if(hostUrl.contains(":")) {
String[] hostUrlParts = hostUrl.split(":");
port = Integer.parseInt(hostUrlParts[1]);
serverAddress = new ServerAddress(hostUrlParts[0], port);
} else {
serverAddress = new ServerAddress(hostUrl);
}
addresses.add(serverAddress);
}
mongo = new Mongo(addresses, mongoOptions);
} else {
mongo = new Mongo(new ServerAddress(host, port), mongoOptions);
}
return mongo;
}