'Not able to connect to remote database through ssh tunneling in java

20:42:08.616 [main] WARN  org.mongodb.driver.uri - Unsupported option 'directconnection' in the connection string 'mongodb://admin:[email protected]:27017/spades-user-service?authSource=admin&readPreference=primary&appname=MongoDB%20Compass&directConnection=true&ssl=false'.
20:42:08.626 [main] WARN  org.mongodb.driver.uri - Unsupported option 'appname' in the connection string 'mongodb://admin:[email protected]:27017/spades-user-service?authSource=admin&readPreference=primary&appname=MongoDB%20Compass&directConnection=true&ssl=false'.
20:42:09.975 [main] INFO  org.mongodb.driver.cluster - Cluster created with settings {hosts=[172.16.0.4:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
20:42:10.225 [main] DEBUG org.mongodb.driver.cluster - Updating cluster description to  {type=UNKNOWN, servers=[{address=172.16.0.4:27017, type=UNKNOWN, state=CONNECTING}]
20:42:10.314 [main] INFO  org.mongodb.driver.cluster - No server chosen by ReadPreferenceServerSelector{readPreference=primary} from cluster description ClusterDescription{type=UNKNOWN, connectionMode=SINGLE, serverDescriptions=[ServerDescription{address=172.16.0.4:27017, type=UNKNOWN, state=CONNECTING}]}. Waiting for 30000 ms before timing out
20:42:30.268 [cluster-ClusterId{value='62067cc9556d842a0ce6c9c7', description='null'}-172.16.0.4:27017] DEBUG org.mongodb.driver.connection - Closing connection connectionId{localValue:1}
20:42:30.280 [cluster-ClusterId{value='62067cc9556d842a0ce6c9c7', description='null'}-172.16.0.4:27017] INFO  org.mongodb.driver.cluster - Exception in monitor thread while connecting to server 172.16.0.4:27017
com.mongodb.MongoSocketOpenException: Exception opening socket
    at com.mongodb.connection.SocketStream.open(SocketStream.java:63) ~[mongodb-driver-core-3.3.0.jar:na]


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source