0

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;
  • So, I get it right: you have two secondaries and a primary, 3 members altogether? – Markus W Mahlberg Nov 06 '15 at 11:13
  • The serverSeeds is a list consisting of ips to secondaries only. In my application we want to read only from the Secondary ones. But in the Mongo Configuration we do have 1 primary, 2 secondaries and 1 arbiter. – user2202967 Nov 06 '15 at 14:06

0 Answers0