Unable to connect to mongodb ec2 instance in java after ec2 restart

I had mongodb instance running on AWS EC2 instance, and I was able to interact with it from java code. Then I had to stop the instance and restart it. I modified the connection details in code. But now when I try to run my application, I get:

com.mongodb.MongoSocketOpenException: Exception opening socket
    at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:70) ~[mongodb-driver-core-4.0.5.jar:na]
    at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:127) ~[mongodb-driver-core-4.0.5.jar:na]
    at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117) ~[mongodb-driver-core-4.0.5.jar:na]
    at java.base/java.lang.Thread.run(Thread.java:832) ~[na:na]

Though I can connect to same mongodb instance via mongo compass.

There should be a nested exception that the MongoSocketOpenException wraps. Can you provide the stack trace for that one too?

1 Like