# Add a MongoDB connector

You can use the Toucan MongoDB connector to connect to your MongoDB cluster with a basic authentication and access `collections` with a aggregation pipeline

With this connection, you can fetch data from your MongoDB cluster to fill your charts and dashboards.

## Configuring a MongoDB connection

Follow the steps described in [..](https://docs-v3.toucantoco.com/data-management-in-datahub/datasources-in-toucan/managing-connectors/setting-up-a-connector "mention"), choose `MongoDB` and fill out the form with the following info:

<table><thead><tr><th>Field</th><th width="140.00390625">Format / Type</th><th>Description</th><th>Example</th></tr></thead><tbody><tr><td>Name (mandatory)</td><td>String</td><td>Use it to identify your connection</td><td><em>MyMongoDBConnection</em></td></tr><tr><td>Host (mandatory)</td><td>String</td><td>The domain name or IP address of your database server, for mongodb atlas you will use the full connection string</td><td><em>mongodb+srv://:@.mongodb.net/?retryWrites=true&#x26;w=majority (</em>Mongo Atlas<em>)</em></td></tr><tr><td>Username (mandatory)</td><td>String</td><td>your login username</td><td><em>my_mongo_user</em></td></tr><tr><td>Password (mandatory)</td><td>String</td><td>Your login password (will be stored as a secret)</td><td><em>my_mongo_password</em></td></tr><tr><td>SSL</td><td>Boolean</td><td>Flag to create the connection using SSL</td><td></td></tr><tr><td>Max_pool_size (optional)</td><td>Integer</td><td>Maximum number of connections in the connection pool</td><td><em>3</em> (default: 1)</td></tr><tr><td>Retry Policy (optional)</td><td>Boolean</td><td><p><em>Boolean</em> allows to configure a retry policy if the connection is flaky.</p><ul><li>max attempts: maximum number of retries before giving up</li><li>max_delay: in seconds, above the connection is dropped</li><li>wait_time: time in seconds between each retry</li></ul></td><td></td></tr><tr><td>Slow Queries' Cache Expiration Time (optional)</td><td>Integer</td><td>Slow queries' cache expiration time in seconds</td><td></td></tr></tbody></table>

Click on the `TEST CONNECTION` button then `SAVE` the connection

{% hint style="success" %}
After successfully configuring the connector, you will be able to find it in the Connector section of the DataHub "Datasource" tab
{% endhint %}

## Create a dataset from a MongoDB connection

To create a dataset from MongoDB, click on the "create from icon", you will then be able to:

* `database`: The name of the database you want to query
* `collection`: The name of the collection you want to query
* Add a Query (optional): Use [MongoDB aggregation pipeline](https://www.mongodb.com/docs/manual/core/aggregation-pipeline/) to queries your collections , and return only the relevant results.
* After inputting your query,
* select "Preview" to review the results,
* and then click "Save" to create a dataset based on your chosen selection.

### Misc

#### Error Handling

The connector handles various error scenarios, including:

* Unknown database (`UnkwownMongoDatabase`)
* Unknown collection (`UnkwownMongoCollection`)
* Connection errors
* Authentication failures

{% hint style="info" %}
For more info, see the dedicated section [creating-datasets](https://docs-v3.toucantoco.com/data-management-in-datahub/datasets-in-toucan/managing-datasets/creating-datasets "mention")
{% endhint %}

{% hint style="success" %}
After selecting data from your connector you will be able to create a dataset thanks to [YouPrep](https://docs-v3.toucantoco.com/data-management-in-datahub/datasets-in-toucan/preparing-data/overview-of-youprep-tm) using the selection as "source step".
{% endhint %}
