I am working on a java application which is trying to read from mongodb. I am using two secondary mongodbs and if one of the db fails, it has to automatically initiate read from the other one. While testing this code I ran into error com.mongodb.MongoTimeoutException: Timed out while waiting to connect after 10000 ms when I stop one of the secondary db(purposefully crashing). What I assume is, the application is not initiating connection to the other mongo. I am at my wits end here and I could use some help. Here's the code snippet of my java application.
initiated=false;
if(initiated){
mongoClient.close();
mongoClient = null;
}
mongoClient = new MongoClient(serverSeeds);
if(isSlaveOk()){
DBObject use = new BasicDBObject("use", "rebel");
DBObject id = new BasicDBObject("id","1");
mongoClient.setReadPreference(ReadPreference.secondaryPreferred(use, id));
}
db = mongoClient.getDB(getDbName());
collection = db.getCollection(getDbCollectionName());
initiated = true;