> ## Documentation Index
> Fetch the complete documentation index at: https://www.aptible.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Connecting to MongoDB fails

If you are connecting to a [MongoDB](/core-concepts/managed-databases/supported-databases/mongodb) [Database](/core-concepts/managed-databases/managing-databases/overview) on Aptible, either through your app or a [Database Tunnel](/core-concepts/managed-databases/connecting-databases/database-tunnels), you might hit an error such as this one:

```sql theme={null}
MongoDB shell version: 3.2.1
connecting to: 172.17.0.2:27017/db
2016-02-08T10:43:40.421+0000 E QUERY    [thread1] Error: network error while attempting to run command 'isMaster' on host '172.17.0.2:27017'  :
connect@src/mongo/shell/mongo.js:226:14
@(connect):1:6

exception: connect failed
```

## 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:

```bash theme={null}
mongo --ssl \
        --username aptible --password "$PASSWORD" \
        --host "$HOST" --port "$PORT"
```
