Reputation: 803
I am trying to connect my Atlas MongoDB instance from Spring Boot using the following properties:
spring.data.mongodb.uri=mongodb+srv://<usr>:<pass>@<my-cluster-prefix>.gkyoqkx.mongodb.net/?retryWrites=true&w=majority
spring.data.mongodb.database=my-db
The connection string I've got from the Atlas "Connect"->"Connect your application" so should be valid. But when I start my app I see the following exception:
2022-08-22 17:13:42.836 INFO 52641 --- [ngodb.net:27017] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server ac-opxd8w6-shard-00-02.gkyoqkx.mongodb.net:27017
com.mongodb.MongoSocketWriteException: Exception sending message
at com.mongodb.internal.connection.InternalStreamConnection.translateWriteException(InternalStreamConnection.java:684) ~[mongodb-driver-core-4.6.1.jar:na]
at com.mongodb.internal.connection.InternalStreamConnection.sendMessage(InternalStreamConnection.java:555) ~[mongodb-driver-core-4.6.1.jar:na]
at com.mongodb.internal.connection.InternalStreamConnection.sendCommandMessage(InternalStreamConnection.java:381) ~[mongodb-driver-core-4.6.1.jar:na]
at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:329) ~[mongodb-driver-core-4.6.1.jar:na]
at com.mongodb.internal.connection.CommandHelper.sendAndReceive(CommandHelper.java:101) ~[mongodb-driver-core-4.6.1.jar:na]
at com.mongodb.internal.connection.CommandHelper.executeCommand(CommandHelper.java:45) ~[mongodb-driver-core-4.6.1.jar:na]
at com.mongodb.internal.connection.InternalStreamConnectionInitializer.initializeConnectionDescription(InternalStreamConnectionInitializer.java:131) ~[mongodb-driver-core-4.6.1.jar:na]
at com.mongodb.internal.connection.InternalStreamConnectionInitializer.startHandshake(InternalStreamConnectionInitializer.java:73) ~[mongodb-driver-core-4.6.1.jar:na]
at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:182) ~[mongodb-driver-core-4.6.1.jar:na]
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.lookupServerDescription(DefaultServerMonitor.java:193) ~[mongodb-driver-core-4.6.1.jar:na]
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:157) ~[mongodb-driver-core-4.6.1.jar:na]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_60]
Caused by: javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternative names matching IP address 34.95.185.60 found
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) ~[na:1.8.0_60]
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1949) ~[na:1.8.0_60]
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302) ~[na:1.8.0_60]
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296) ~[na:1.8.0_60]
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1506) ~[na:1.8.0_60]
at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216) ~[na:1.8.0_60]
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:979) ~[na:1.8.0_60]
at sun.security.ssl.Handshaker.process_record(Handshaker.java:914) ~[na:1.8.0_60]
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1062) ~[na:1.8.0_60]
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375) ~[na:1.8.0_60]
at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:747) ~[na:1.8.0_60]
at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:123) ~[na:1.8.0_60]
at com.mongodb.internal.connection.SocketStream.write(SocketStream.java:99) ~[mongodb-driver-core-4.6.1.jar:na]
at com.mongodb.internal.connection.InternalStreamConnection.sendMessage(InternalStreamConnection.java:552) ~[mongodb-driver-core-4.6.1.jar:na]
... 10 common frames omitted
which is looking strange since by default it shouldn't be using SSL to connect (afaik).
I also whitelisted all IPs by adding 0.0.0.0/0
to the Network Access in Atlas.
And btw, when I am trying to connect from my Mac with mongosh
and the same connection URI it works perfectly.
Any piece of advice is appreciated.
Atlas MongoDB version: 5.0.10, Mongo driver version: 4.6.1
Upvotes: 1
Views: 1525
Reputation: 1
Don't do anything with java version just go to mongoDb atlas homepage and then go to network access page and add the current IP.
Upvotes: 0
Reputation: 81
Same issue here, I fixed it upgrading Java version from 11 to 17, you shoud try it as an alternative solution. This is a known bug in mongodb-driver-sync with JKD 13.0.2, solved in Java versions >= 13.0.5. check official mongo forum discussion here
The question is: to upgrade Java is not a solution if the issue is according to the connection driver. I'll come here again if I find something new.
Upvotes: 2