# MongoDB

Connect RootCause.ai 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.ai to your MongoDB instance
* Read access to the databases and collections you want to import

***

### Setting Up the Connection

1. Navigate to **Data** → **Datasets** in your workspace
2. Click **New Connection** and select **MongoDB**
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.ai 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.

***

### What Happens When You Import

1. RootCause.ai 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
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

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.ai
* 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.ai
* 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


---

# 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.rootcause.ai/data-connectors/mongodb.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.
