> AI agents: this is one page from Mammoth Analytics documentation. The index of all pages as Markdown is https://docs.mammoth.io/llms.txt. Append `.md` to any docs URL, or send `Accept: text/markdown`, to get Markdown.

# MongoDB connector

> Connect Mammoth to MongoDB: required access, how to create a connection, and how to import a collection or SQL query as a dataset.

The MongoDB connector imports data from your MongoDB database into Mammoth as a dataset. Select a collection from the browser or write a query to import documents as rows.

## Before you start

You need:

- A MongoDB instance accessible from the internet
- A MongoDB user with `read` access on the database you want to import from
- Your server's hostname, port (default: 27017), database name, username, and password
- Mammoth's IP address added to your MongoDB network allowlist—see [Network requirements](https://docs.mammoth.io/learn/connectors/network-requirements/)

## Step 1: Select the MongoDB connector

1. In Mammoth, go to **Data Library** and click **+ New Dataset**
2. Select **Connectors**
3. Search for **MongoDB**
4. Click the **MongoDB** tile

## Step 2: Create a connection

Click **New Connection** to open the credential form.

![MongoDB New Connection form with Host URL, Port 27017, Username, Password, Database, and Display Name fields](https://docs.mammoth.io/api/v1/images/20260615_102934_Screenshot2026-05-211505091.jpg)

| Field | Description | Example |
| --- | --- | --- |
| **Host URL** | Hostname or IP address of your MongoDB server | `mongo.example.com` |
| **Port** | TCP port MongoDB listens on | `27017` (default) |
| **Username** | MongoDB user with read access | `mammoth_reader` |
| **Password** | Password for the user |—|
| **Database** | Name of the MongoDB database | `analytics` |
| **Display Name** | Optional label for this connection | `MongoDB Atlas` |

> **Tip: MongoDB Atlas.**
> If you're using MongoDB Atlas, find your connection hostname in **Atlas → Database → Connect → Connect your application**. It looks like `cluster0.abc123.mongodb.net`. Use port `27017` and add Mammoth's IP address to your Atlas **Network Access** allowlist.

After filling in the fields, click **Connect**. Mammoth validates the credentials and saves the connection; if validation fails, the error message appears at the bottom of the form.

## Step 3: Select a MongoDB collection and query your data

After you connect, select the connection under **Existing Connections** to open the query builder. The **List of tables** panel shows the collections in your database. Click a collection name to load a `SELECT *` query for it and its preview.

### Write a custom MongoDB query

Use the **Enter SQL query** editor to filter documents or select specific fields. You query your MongoDB collections with SQL:

```sql
SELECT _id, name, email, createdAt
FROM customers
WHERE status = 'active'
```

![MongoDB New Dataset dialog with collection list, SELECT query, preview of three rows, and Dataset saved message](https://docs.mammoth.io/api/v1/images/20260615_102954_Screenshot2026-05-211511351.jpg)

See [Understanding data preview & query](https://docs.mammoth.io/learn/connectors/understanding-data-preview-query/) for a full guide.

## Step 4: Save the MongoDB dataset

1. Enter a **dataset name** in the **Save table as** field
2. Check the **Update Method** (the default is **Replace all data**). To change it, click the edit icon, pick an option, and click **Save changes**:
   - **Replace all data**—Replaces all existing data
   - **Add new data**—Adds new data based on a unique sequential column
   - **Replace with new data**—Replaces existing data with new data based on a unique sequential column
   For **Add new data** and **Replace with new data**, also choose a **Key column**—a numeric or date column with incrementing values, such as an ID or a date.
3. Click **Save as dataset**. When the dataset is saved, click **Done**

![MongoDB New Dataset dialog with Save table as, Update Method, and Save as dataset button below the preview](https://docs.mammoth.io/api/v1/images/20260615_103011_Screenshot2026-05-211512401.jpg)

## Troubleshoot MongoDB connections

### Connection fails

- Confirm port 27017 is open inbound from Mammoth's IP address
- For MongoDB Atlas, check your **Network Access** list in the Atlas console
- Verify the user has `read` role on the database: `db.grantRolesToUser("mammoth_reader", [{ role: "read", db: "analytics" }])`

---
Source: https://docs.mammoth.io/learn/connectors/mongodb.md · Updated: 2026-10-13