# 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 %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs-v3.toucantoco.com/data-management-in-datahub/datasources-in-toucan/managing-connectors/setting-up-a-connector/database-and-data-warehouse-connectors/setting-up-a-mongodb-connector.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
