0

I'm experiencing occasional com.mongodb.MongoTimeoutException errors on AWS when connecting to a replica set. I'm connecting using the domain name that's being outputed from rs.status(), for example, mongo1.production and mongo2.production but I still get the timeouts.

My code looks like:

MongoClientOptions options = new MongoClientOptions.Builder()
                    .writeConcern(WriteConcern.ACKNOWLEDGED)
                    .readPreference(ReadPreference.primaryPreferred())
                    .connectTimeout(30000)
                    .socketTimeout(60000)
                    .connectionsPerHost(50)
                    .threadsAllowedToBlockForConnectionMultiplier(10)
                    .build();

List<ServerAddress> seeds = new ArrayList<ServerAddress>();
seeds.add(new ServerAddress("mongo1.production:27017"));
seeds.add(new ServerAddress("mongo2.production:27017"));
MongoClient client = new MongoClient(seeds, null, options);
Mark
  • 67,098
  • 47
  • 117
  • 162
  • Can you provide a full stack trace, including the root cause of the MongoTimeoutException? Also, please provide the Java driver version and the server version. – jyemin Jul 21 '14 at 17:38

1 Answers1

0

If you try to run mongo from Terminal by typing...

mongod

...you will (probably) get the following error:

*********************************************************************
 ERROR: dbpath (/data/db) does not exist.
 Create this directory or give existing directory in --dbpath.
 See http://dochub.mongodb.org/core/startingandstoppingmongo
*********************************************************************

All you have to do is to create the directory/path that mongo is looking for (/data/db) like this:

sudo mkdir -p /data/db/

and then:

sudo chown `id -u` /data/db

Alternatively and as mentioned in the error message, you can give an existing directory in --dbpath like this:

mongod --dbpath /srv/mongodb/

For more details check the MongoDB manual.

consuela
  • 1,675
  • 6
  • 21
  • 24