we are using only one instance of mongos and after some time run one more instance of it, but My java client is not able to send the request to the newly added mongos instance.
Hi Sumit,
You can specify a list of mongos
instances, for example using ServerAddress
:
MongoClient mongoClient = MongoClients.create(
MongoClientSettings.builder()
.applyToClusterSettings(builder ->
builder.hosts(Arrays.asList(
new ServerAddress("mongos_01", 27019),
new ServerAddress("mongos_02", 27019))))
.build());
See also MongoDB Java Driver: Connect to a sharded cluster
Regards,
Wan