「MongoDB入門」Javaで複数のMongoサーバーに接続するサンプル
Javaコード
MongoCliant cliant = new MongoCliant();
String host = “172.17.2.200";
MongoCliant cliant = new MongoCliant(host, 27017);
//複数のサーバーを対象としたアクセス
ServerAddress sa1 = new ServerAddress(“userServer", 27017);
ServerAddress sa2 = new ServerAddress(“empServer", 27017);
List<ServerAddress> cftAddr = new ArrayList<>(Arrays.asList(sa1, sa2));
MongoCliant cliant = new MongoCliant(cftAddr);