> For the complete documentation index, see [llms.txt](https://docs.onum.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.onum.com/data-sinks/data-sink-integrations/send-data-to-mongodb.md).

# Send data to MongoDB

{% hint style="info" %}
See the changelog of the **Mongo DB** sink type [here](/data-sinks-changelog/mongodb-data-sink.md).
{% endhint %}

## Overview

Onum supports integration with [MongoDB](https://www.mongodb.com/).

MongoDB is a document database used to build highly available and scalable internet applications. Instead of using tables, as in a traditional relational database, MongoDB stores data in JSON documents organized into collections.

## Prerequisites&#x20;

The MongoDB **server** or **cluster** must have its firewall configured to explicitly allow inbound traffic.

Make sure to have your connection string (URI) at the ready to establish the connection. This string typically includes:

* The MongoDB protocol (`mongodb+srv://` for Atlas or `mongodb://` for self-managed).
* The username and password.
* The cluster/server address and port.
* Any necessary query parameters (e.g., authentication method).

## Onum Setup

{% stepper %}
{% step %}
Log in to your Onum tenant and click **Data Sinks> New Data sink**.
{% endstep %}

{% step %}
Double-click the **MongoDB** Sink.
{% endstep %}

{% step %}
Enter a **Name** for the new Data Sink. Optionally, add a **Description** and some **Tags** to identify the Sink.
{% endstep %}

{% step %}
Decide whether or not to include this Data sink info in the metrics and graphs of the [**Home**](/home.md) area.
{% endstep %}

{% step %}
**Authentication Method**

Select one of the following options and complete the fields that appear to authenticate your connection:

<details>

<summary><strong>SRV Connection String</strong></summary>

Enter the **Host**<mark style="color:red;">**\***</mark> URL to connect to a MongoDB cluster using DNS-based seedlists. To get it:

1. Log in to MongoDB.
2. Choose the project that contains your cluster.
3. Click on the **Clusters** tab in the left-hand sidebar.
4. For the cluster you want to connect to, click the **Connect** button.
5. Select **Connect your application** for the connection method.
6. Copy the SRV Connection String, which should have the following format:&#x20;

```
mongodb+srv://:@cluster0.abcde.mongodb.net/myDatabase?retryWrites=true&w=majority
```

* Replace `username` and  `password` with your database credentials.
* Replace `myDatabase` with your target database name.

</details>

<details>

<summary><strong>Standard Connection String</strong></summary>

Enter the required **Host**<mark style="color:red;">**\***</mark> and **Port**<mark style="color:red;">**\***</mark> for a standard MongoDB connection string (non-SRV). To get the host:

1. Log in to MongoDB Atlas.
2. Select your **project** and **cluster**.
3. Click the **Connect** button for your cluster.
4. Choose **Connect your application**.
5. Click **I don’t have a driver** or scroll down to find the **standard connection string** option. You’ll see something like:

```plaintext
plaintextCopyEditmongodb://<username>:<password>@cluster0-shard-00-00.abcde.mongodb.net:27017,cluster0-shard-00-01.abcde.mongodb.net:27017,cluster0-shard-00-02.abcde.mongodb.net:27017/myDatabase?ssl=true&replicaSet=atlas-abcde-shard-0&authSource=admin&retryWrites=true&w=majority
```

* Replace `username` and  `password` with your database credentials.
* Replace `myDatabase` with your target database name.

</details>
{% endstep %}

{% step %}
**Authentication configuration**

Choose your required authentication **Type**<mark style="color:red;">**\***</mark> from the dropdown menu. Leave as **None** if no authentication is needed, or select from the following:

<table><thead><tr><th width="170.30859375">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><strong>SCRAM-SHA-256</strong></td><td><ul><li><strong>Username</strong><mark style="color:red;"><strong>*</strong></mark> - Enter your required username.</li><li><strong>Password</strong><mark style="color:red;"><strong>*</strong></mark> - Add your password from your <a href="/pages/YAQlTald3E2cheY5V0Hk">Secrets</a> or create one.</li><li><strong>Auth source</strong> - This is the database where your credentials are stored. For example:  <code>mongodb://username:password@host:port/?authSource=admin</code> </li></ul></td></tr><tr><td><strong>SCRAM-SHA-1</strong></td><td><ul><li><strong>Username</strong><mark style="color:red;"><strong>*</strong></mark> - Enter your required username.</li><li><strong>Password</strong><mark style="color:red;"><strong>*</strong></mark> - Add your password from your <a href="/pages/YAQlTald3E2cheY5V0Hk">Secrets</a> or create one.</li><li><strong>Auth source</strong> - This is the database where your credentials are stored. For example:  <code>mongodb://username:password@host:port/?authSource=admin</code> </li></ul></td></tr><tr><td><strong>x.509</strong></td><td><ul><li><strong>Client certificate</strong><mark style="color:red;"><strong>*</strong></mark> - Add your client certificate from your <a href="/pages/YAQlTald3E2cheY5V0Hk">Secrets</a> or create one.</li><li><strong>Client private key</strong><mark style="color:red;"><strong>*</strong></mark> - Add your private key from your <a href="/pages/YAQlTald3E2cheY5V0Hk">Secrets</a> or create one.</li><li><strong>CA certificate</strong><mark style="color:red;"><strong>*</strong></mark> - Add your CA certificate from your <a href="/pages/YAQlTald3E2cheY5V0Hk">Secrets</a> or create one.</li><li><strong>Auth source</strong> - This is the database where your credentials are stored. For example:  <code>mongodb://username:password@host:port/?authSource=admin</code> </li></ul></td></tr><tr><td><strong>AWS IAM</strong></td><td><ul><li><p><strong>Access key ID</strong><mark style="color:red;"><strong>*</strong></mark> - Add the access key ID from your <a href="/pages/YAQlTald3E2cheY5V0Hk">Secrets</a> or create one. The <strong>Access Key ID</strong> is found in the <strong>IAM Dashboard</strong> of the <strong>AWS Management Console</strong>. To get it:</p><ol><li>In the left panel, click on <strong>Users</strong>.</li><li>Select your <strong>IAM user</strong>.</li><li>Under the <strong>Security Credentials</strong> tab, scroll to <strong>Access Keys</strong>, and you will find existing <strong>Access Key IDs</strong> (but not the secret access key).</li></ol></li><li><strong>Access key</strong><mark style="color:red;"><strong>*</strong></mark> - Add the access key from your <a href="/pages/YAQlTald3E2cheY5V0Hk">Secrets</a> or create one. Under <strong>Access keys</strong>, you can see your <strong>Access Key IDs</strong>, but AWS <strong>will not show the Secret Access Key</strong>.  </li><li><p><strong>AWS session token</strong> - Add the AWS token from your <a href="/pages/YAQlTald3E2cheY5V0Hk">Secrets</a> or create one. To get it:</p><ol><li>Log in to the <strong>AWS Management Console</strong> via IAM Identity Center.</li><li>Click your <strong>username</strong> in the top-right corner and choose <strong>Command line or programmatic access</strong>.</li></ol></li><li><strong>Auth source</strong> - This is the database where your credentials are stored. For example:  <code>mongodb://username:password@host:port/?authSource=admin</code> </li></ul></td></tr></tbody></table>
{% endstep %}

{% step %}
Click **New secret** to create a new one:

* Give the secret a **Name**.
* Turn off the **Expiration date** option.
* Click **Add new value** and paste the corresponding value.
* Click **Save**.

<figure><picture><source srcset="/files/NeeWsSQzoChVxRIY76Nt" media="(prefers-color-scheme: dark)"><img src="/files/1oTccyPmgZJ1laY7IhZH" alt=""></picture><figcaption></figcaption></figure>

{% hint style="info" %}
Learn more about secrets in Onum in [this article](/settings/organization-settings/secrets-management.md).
{% endhint %}

You can now select the created secrets in the configuration.
{% endstep %}

{% step %}
Set the **Connection pool** settings

* **Max pool size -** Set a limit on the number of events per pool. The minimum value is `0` and the maximum value is `10000`. The default value is `100`.
* **Min pool size -** Set a minimum number of events per pool. The minimum value is `1` and the maximum value is `10000`. The default value is `10`.
* **Max idle time -** Set the maximum amount of milliseconds a request can be idle before being considered timed out. The minimum value is `0` and the maximum value is `300000`. The default value is `30000`.
* **Max simultaneous connections -** Enter a maximum allowance for the number of simultaneous connections. The minimum value is `1` and the maximum value is `1000`. The default value is `100`.
  {% endstep %}

{% step %}
Toggle on the **Bulk configuration** switch button to enable bulk settings. The values will be filled in by default; however, you can change them if needed.

* **Number of events**<mark style="color:red;">**\***</mark> Enter a maximum for the number of events in a bulk. The minimum value is `1` and the maximum value is `1000`. The default value is `10`.
* **Event time limit**<mark style="color:red;">**\***</mark> Enter the number of seconds to wait before a bulk is triggered. The minimum value is `0` and the maximum value is `30000`. The default value is `1`.
* **Max number of buffers**<mark style="color:red;">**\***</mark> Enter the maximum buffers that a system, application, or service is allowed to allocate or use for storing temporary data while processing it. The minimum value is `1` and the maximum value is `50`. The default value is `50`.
* **Ordered** You can toggle on this switch button to send the buffers in order.
  {% endstep %}

{% step %}
Toggle on the **Bypass Document Validation** switch button to allow MongoDB to skip any schema validation rules or constraints that would normally be enforced when inserting or updating a document.
{% endstep %}
{% endstepper %}

Click **Finish** when complete. Your new Data sink will appear in the **Data sinks** area list.

## Pipeline configuration <a href="#pipeline-configuration" id="pipeline-configuration"></a>

When it comes to using this Data sink in a [Pipeline](/pipelines.md), you must configure the following output parameters. To do it, simply click the Data sink on the canvas and select **Configuration**.

### Output configuration <a href="#output-configuration" id="output-configuration"></a>

<table><thead><tr><th width="170.32421875">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><strong>Database</strong><mark style="color:red;"><strong>*</strong></mark></td><td>Choose the input field that contains the name of the database you want to write to.</td></tr><tr><td><strong>Collection</strong><mark style="color:red;"><strong>*</strong></mark></td><td>Choose the input field that contains the name of the collection you want to write to.</td></tr><tr><td><strong>Data</strong><mark style="color:red;"><strong>*</strong></mark></td><td>Choose the input field that contains the data to be sent to MongoDB.</td></tr></tbody></table>

Click **Save** to save your configuration.
