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

# MongoDB

Connect RootCause to your MongoDB database to import collections with optional query filters.

***

### Prerequisites

Before connecting, ensure you have:

* MongoDB connection string (including authentication if required)
* Network access from RootCause to your MongoDB instance
* Read access to the databases and collections you want to import

***

### Setting Up the Connection

1. Navigate to **Sources** in your workspace and click **Import data**
2. In the Import Manager, find **MongoDB** and click **Setup**
3. Enter your connection string:

| Field             | Description      | Example                                       |
| ----------------- | ---------------- | --------------------------------------------- |
| Connection String | Full MongoDB URI | `mongodb+srv://user:pass@cluster.mongodb.net` |

**Connection String Formats:**

* **Standard:** `mongodb://username:password@host:27017`
* **Atlas (SRV):** `mongodb+srv://username:password@cluster.mongodb.net`
* **Replica Set:** `mongodb://host1:27017,host2:27017/?replicaSet=mySet`

4. Click **Test Connection** to verify your credentials
5. Click **Save** to create the connector

***

### Importing Data

Once your connector is saved:

1. Click **Import Data** on the connector
2. Select a **Database** from the dropdown (RootCause will list available databases)
3. Select a **Collection** from the dropdown
4. Optionally, add a **Query Filter** to import only matching documents

**Query Filter Example:**

```json
{
  "status": "active",
  "createdAt": { "$gte": { "$date": "2024-01-01T00:00:00Z" } }
}
```

The query filter uses standard MongoDB query syntax.

**Import Options**

Under **Advanced Options**, you can control how documents are converted into a table:

| Option           | Default | Description                                                                 |
| ---------------- | ------- | --------------------------------------------------------------------------- |
| Flatten Depth    | `2`     | How many levels of nested objects are flattened into separate columns (1–5) |
| Stringify Arrays | On      | Convert arrays to JSON strings for tabular compatibility                    |

***

### What Happens When You Import

1. RootCause connects to your MongoDB instance
2. Documents from the selected collection are retrieved (with optional filter)
3. Nested documents are flattened into a tabular format (up to the configured flatten depth; arrays are stringified if enabled)
4. Schema is automatically detected from the document structure
5. Data is stored securely in your workspace's data lake

The imported dataset becomes available for use in [Data Views](/user-guide/data-views.md) and [Ontology](/core-technologies/ontology.md) mapping.

***

### Live Data Sync

You can configure automatic syncing to keep your dataset current:

* **Manual** – Only sync when you click "Sync Now"
* **Hourly** – Refresh every hour
* **Daily** – Refresh once per day
* **Weekly** – Refresh once per week
* **Monthly** – Refresh once per month

When a sync runs, the entire dataset is replaced with fresh data from the source.

***

### Security Recommendations

* Use a dedicated read-only user for RootCause
* Include authentication in your connection string
* Use TLS/SSL connections (append `?tls=true` if needed)
* For Atlas, use IP allowlisting to restrict access

***

### Troubleshooting

**Connection timeout**

* Verify the connection string is correct
* Check that your MongoDB instance is accessible from RootCause
* For Atlas, ensure the IP address is in your allowlist

**Authentication failed**

* Verify username and password in the connection string
* Ensure the user exists in the `admin` database or the target database
* Check authentication mechanism compatibility

**Database or collection not showing**

* Verify the user has `listDatabases` and `listCollections` permissions
* Check that the database/collection exists and contains documents
