Can I have an instance of more than 1 'mongos?

I am using Java to insert data into a mongodb cluster. Can I have more than 1 instance of mongos so that I have a backup when one of my Mongols is down?

Here is my java code for connecting to mongo.

MongoClient mongoClient = new MongoClient("10.4.0.121",6001); DB db = mongoClient.getDB("qbClientDB"); DBCollection collection = db.getCollection("clientInfo"); 

How can I specify my second mongos instance in my Java code? (If it is possible).

Thanks in advance.

+7
java mongodb
source share
2 answers
  public MongoClient(List<ServerAddress> seeds, MongoClientOptions options) //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. //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. MongoClient mongoClient = new MongoClient(Arrays.asList( new ServerAddress("10.4.0.121",6001), new ServerAddress("10.4.0.122",6001), new ServerAddress("10.4.0.123",6001))); 
+4
source share

MongoClient docs say you can do something similar to (dummy addresses);

 MongoClient mongoClient = new MongoClient(Arrays.asList( new ServerAddress("10.4.0.121",6001), new ServerAddress("10.4.0.122",6001), new ServerAddress("10.4.0.123",6001))); 

MongoClient will automatically detect whether the servers are a list of replica set members or a list of mongos servers.

+5
source share

All Articles