1

I have configured my production environment with the following details:

1. Three config server
2. Two routers (`mongos`)
3. Two shards of three node replica sets.

My question is: I am trying to connect to the sharded database with the help of the mongo java driver. So, if I give my two mongos IPs for connection, how will the driver select one mongos for routing data, in other words which mongos will be selected as the primary router and how will the other one be picked if one goes down.

Adam C
  • 5,132
  • 2
  • 28
  • 49

1 Answers1

0

When you create your MongoClient in the driver, you simply give it a list of mongos to use rather than a single mongos - the driver will then automatically fail over if one goes down. Check the relevant API docs here:

http://api.mongodb.org/java/2.11.3/com/mongodb/MongoClient.html#MongoClient(java.util.List)

Adam C
  • 5,132
  • 2
  • 28
  • 49