Connecting MongoDB to Metabase with self-signed certificate

I've a Mongo database with the follow URI schema: mongodb://username:password@url1:port,url2:port/database?authSource=admin&ssl=true and I can't connect Metabase BI to my database.

The image below is how I'm setting up the database:

I was getting the follow error:

com.mongodb.MongoTimeoutException: Timed out after 3000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=url:port, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketReadException: Prematurely reached end of stream}}]

I've tried to see this solution here opened on Metabase Discussion but I didn't succeed cause I have no certificate and I usually connect to my database using 'sslAllowInvalidCertificates'. Furthermore, when I create a certificate as has taught on this link and now I'm getting the follow error:

"dbname":"com.mongodb.MongoTimeoutException: Timed out after 3000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=url:port, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: url}, caused by {java.net.UnknownHostException: url}}]"

Could someone help me?

Hi @vitoresende
I don’t run MongoDB, but since it’s saying Prematurely reached end of stream, I would think you would see the connection failing in your MongoDB log - do you see anything there?

Unfortunately I don’t have access to these kind of data or logs. And I updated the error, now I’m getting the error java.net.UnknownHostException

But that sounds like the address in Server field is wrong. Can you ping that hostname from the same server that runs Metabase?

I can’t :confused:

UnknownHostException was due my network connection. But now, I’m getting the follow error:

“com.mongodb.MongoTimeoutException: Timed out after 3000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address:38796=sl-us-south-1-portal.22.dblayer.com, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketWriteException: Exception sending message}, caused by {javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target}, caused by {sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target}, caused by {sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target}}]”

Could someone help me?

Are you using a self-signed certificate? Then you might be seeing this issue - there are some workarounds:

I was answering the topic cause I've found this solution and I tried what j005u said there. And I've got the same error of before: "Prematurely reached end of stream". I've tried everything build manually and using Docker, but nothing is working :frowning: