Connecting to MongoDB fails
If you are connecting to a MongoDB Database on Aptible, either through your app or a Database Tunnel, you might hit an error such as this one:
Cause
This error is usually caused by attempting to connect without SSL to a MongoDB server that requires it, which is the case on Aptible.
Resolution
To solve the issue, connect to your MongoDB server over SSL.
Clients
Connection URLs generated by Aptible include the ssl=true
parameter, which should instruct your MongoDB client to connect over SSL. If your client does not connect over SSL despite this parameter, consult its documentation.
CLI
📘 Make sure you use a hostname to connect to MongoDB databases when using a database tunnel. If you use an IP address for the host, certificate verification will fail. You can work with
--sslAllowInvalidCertificates
in your command line, but using a hostname is simpler and safer.
The MongoDB CLI client does not accept database URLs. Use the following to connect:
Was this page helpful?