My Spring Boot App is able to connect with DB deployed in MongoDB Atlas, but when I try to connect with the one in EC2 I’m unable to do so.
Setup:
MongoDB : 7.0
Replication: enabled
Server: Linux EC2
Config: 3 node 1 instance
Spring Boot: Inside Docker
Mongodb URl: mongodb://dbadmin:pwd@Public_IP:37011,Public_IP:37022,Public_IP:37033/testdb?replicaSet=ReplSet1&authSource=admin&connectTimeoutMS=300000
While try to run the application, I’m getting following error–>
<Caused by: com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches com.mongodb.client.internal.MongoClientDelegate$1@519f7d59. Client view of cluster state is {type=REPLICA_SET, servers=[{address=Public_IP:37033, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: Connect timed out}}, {address=Public_IP:37011, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: Connect timed out}}, {address=Public_IP:37022, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: Connect timed out}}]
at com.mongodb.internal.connection.BaseCluster.createTimeoutException(BaseCluster.java:403) ~[mongodb-driver-core-4.0.4.jar:na]
at com.mongodb.internal.connection.BaseCluster.selectServer(BaseCluster.java:118) ~[mongodb-driver-core-4.0.4.jar:na]
at com.mongodb.internal.connection.AbstractMultiServerCluster.selectServer(AbstractMultiServerCluster.java:54) ~[mongodb-driver-core-4.0.4.jar:na]
at com.mongodb.client.internal.MongoClientDelegate.getConnectedClusterDescription(MongoClientDelegate.java:149) ~[mongodb-driver-sync-4.0.4.jar:na]
at com.mongodb.client.internal.MongoClientDelegate.createClientSession(MongoClientDelegate.java:98) ~[mongodb-driver-sync-4.0.4.jar:na]
at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.getClientSession(MongoClientDelegate.java:278) ~[mongodb-driver-sync-4.0.4.jar:na]
at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:182) ~[mongodb-driver-sync-4.0.4.jar:na]
at com.mongodb.client.internal.MongoIterableImpl.execute(MongoIterableImpl.java:135) ~[mongodb-driver-sync-4.0.4.jar:na]
at com.mongodb.client.internal.MongoIterableImpl.iterator(MongoIterableImpl.java:92) ~[mongodb-driver-sync-4.0.4.jar:na]
at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:2771) ~[spring-data-mongodb-3.0.1.RELEASE.jar:3.0.1.RELEASE]
… 88 common frames omitted>
Any suggestions would be a great assistance.