First of all - I am using MongoDB java driver 3.12.2
I have created an project on atlas (using the free plan, so shared cluster) and am having trouble connecting to it using the java driver.
Currently, I code I am using for connecting looks like this:
MongoClient mongoClient = MongoClients.create("mongodb+srv://excel:<password>@excelerate.svfgy.mongodb.net/database?retryWrites=true&w=majority");
database = mongoClient.getDatabase("database");
collection = database.getCollection("collection-1");
And that works completely fine. However, when I try to search for a document in the database using code which looks like this:
database.getCollection().find(Filters.eq("user-id", this.userId)).first();
I get a very long exception:
com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches com.mongodb.client.internal.MongoClientDelegate$1@7e32e7b1. Client view of cluster state is {type=REPLICA_SET, servers=[{address:27017=excelerate-shard-00-01.svfgy.mongodb.net, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketWriteException: Exception sending message}, caused by {javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternative names matching IP address 18.158.163.233 found}, caused by {java.security.cert.CertificateException: No subject alternative names matching IP address 18.158.163.233 found}}, {address:27017=excelerate-shard-00-00.svfgy.mongodb.net, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketWriteException: Exception sending message}, caused by {javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternative names matching IP address 18.185.151.83 found}, caused by {java.security.cert.CertificateException: No subject alternative names matching IP address 18.185.151.83 found}}, {address:27017=excelerate-shard-00-02.svfgy.mongodb.net, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketWriteException: Exception sending message}, caused by {javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternative names matching IP address 3.122.218.128 found}, caused by {java.security.cert.CertificateException: No subject alternative names matching IP address 3.122.218.128 found}}]
My initial thoughts were that this was an authentication issue - so I triple checked that my network access was set to “access from anywhere”, username and password were correct.
Another small thing I took notice of was that even if your password is incorrect in the connection URI, the MongoClients.create won’t throw an exception.
Also I tried connecting to the database in the mongo shell, and that seems to work just fine, which led me to think that this is an issue with the driver (which is why this is in the drivers section and not atlas section).
I have done numerous google searches to figure this out, and I can’t find anyone with the exact exception I got.
Any help is greatly appreciated, and if you need more information I will add that as soon as I get a chance.