com.mongodb.MongoTimeoutException: Timed out after 10000 ms while waiting to connect

You obtain a Connection refused. Are you sure mongod is running?

Try to connect with mongoclient:

mongo 127.0.0.1:27000/test

and this for all the three instances (27000, 27002, 27001).

If you have problem also with mongoclient, check your logs.


another reason for this error can be that the version of mongo-java-driver is not compatible with your mongo application. My case : I was using mongo-java-driver version 2.12.3 with mongo 3.0.8 -> doesn't work. (https://docs.mongodb.com/ecosystem/drivers/driver-compatibility-reference/#reference-compatibility-mongodb-java)


Here is all the possible reason for this error are listed. In my case it was due to replicaset not initialised. Initialise replicaset using rs.initiate(). In my case I used the volume created from production data and used it in staging. Since the local db was having old replicaset config, it was not able to become PRIMARY. I did the following thing to make it PRIMARY:

>use local
> db.dropDatabase();
{ "dropped" : "local", "ok" : 1 }
> rs.initiate()
>myrepl:PRMIARY

Now the client was able to connect and perform read/write operations.