> ## Documentation Index
> Fetch the complete documentation index at: https://ngquct-feat-721-compare-sync.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# MongoDB

> Connect to MongoDB with MQL shell queries, collection browsing, and automatic Atlas SRV setup

Collections appear as tables in the sidebar. Documents display with top-level fields as columns and nested objects as formatted JSON.

MongoDB is a registry plugin. Picking it in the **Choose a Database** sheet prompts to install; connecting to a saved MongoDB connection installs it without asking. You can also install **MongoDB Driver** from **Settings > Plugins > Browse**.

## Quick Setup

<Steps>
  <Step title="Create Connection">
    Click **New Connection**, select **MongoDB**, enter hosts and credentials, and click **Create**
  </Step>

  <Step title="Test Connection">
    Click **Test Connection** to verify
  </Step>
</Steps>

## Connection Settings

| Field              | Default           | Notes                                                                        |
| ------------------ | ----------------- | ---------------------------------------------------------------------------- |
| **Hosts**          | `localhost:27017` | Add multiple `host:port` pairs for replica sets                              |
| **Username**       | -                 | Leave empty for local dev without auth                                       |
| **Password**       | -                 |                                                                              |
| **Auth Mechanism** | Default           | SCRAM-SHA-1, SCRAM-SHA-256, X.509, or AWS IAM. In the Authentication section |

The form has no Database field. On connect TablePro opens the first non-system database it finds, and **Cmd+K** switches to another. A database in a connection URL path (`mongodb://host:27017/mydb`) is used instead.

**Advanced**: **Auth Database** (usually `admin`), **Read Preference**, **Write Concern**, **Use SRV Record**, and **Replica Set** name.

<Frame caption="MongoDB connection form">
  <img className="block dark:hidden" src="https://mintcdn.com/ngquct-feat-721-compare-sync/Px1jOVnHwSdgRuFN/images/mongodb-connection-form.png?fit=max&auto=format&n=Px1jOVnHwSdgRuFN&q=85&s=99683a6de29354132eda304fcfd187bb" alt="MongoDB connection form with the multi-host Hosts editor" width="1560" height="960" data-path="images/mongodb-connection-form.png" />

  <img className="hidden dark:block" src="https://mintcdn.com/ngquct-feat-721-compare-sync/Px1jOVnHwSdgRuFN/images/mongodb-connection-form-dark.png?fit=max&auto=format&n=Px1jOVnHwSdgRuFN&q=85&s=006fa32b65e399c2f512e05b7dcb0cd3" alt="MongoDB connection form with the multi-host Hosts editor" width="1560" height="960" data-path="images/mongodb-connection-form-dark.png" />
</Frame>

## MongoDB Atlas (SRV)

The **Use SRV Record** toggle in Advanced connects with the `mongodb+srv://` scheme. For hosts ending in `.mongodb.net`, TablePro enables SRV automatically and turns TLS on if the SSL mode is Disabled, since Atlas requires both. An Atlas connection needs only the cluster hostname, username, and password.

## Replica Sets

The **Hosts** field accepts multiple `host:port` pairs separated by commas (for example `host1:27017,host2:27017,host3:27017`). TablePro discovers the primary automatically and routes writes there. Set the replica set name in **Advanced**.

You can also paste a multi-host URI directly:

```text theme={null}
mongodb://user:pass@host1:27017,host2:27017,host3:27017/db?replicaSet=rs0
```

<Note>
  Over an SSH tunnel TablePro connects to the first host only and drops the rest of the list. Replica set discovery and failover are off for that session.
</Note>

## SSL/TLS

The MongoDB driver has no TLS fallback. **Preferred** behaves the same as **Required** (the SSL pane shows a warning). For unencrypted local instances, use **Disabled** or [SSH tunneling](/databases/ssh-tunneling). See [SSL/TLS](/features/ssl) for details.

## Connection URL

```text theme={null}
mongodb://user:password@host:27017/database?authSource=admin
mongodb+srv://user:password@cluster.mongodb.net/database
```

The `mongodb+srv://` scheme resolves hosts through DNS SRV records and does not allow a port. If you paste an SRV URL that includes one (for example `cluster.mongodb.net:27017`), TablePro strips it before connecting. The plain `mongodb://` scheme keeps any port you provide.

See [Connection URL Reference](/databases/connection-urls) for all parameters.

## Features

**Collection Browsing**: Sidebar shows all collections. Click to view documents in the data grid. Top-level fields render as columns, nested objects and arrays as formatted JSON, ObjectIds as strings. The grid schema is inferred by sampling documents.

**Views**: **New View** in the sidebar opens a query tab with a `db.createView("view_name", "source_collection", [pipeline])` template. Editing a view definition pre-fills a `db.runCommand({"collMod": ...})` command.

**Explain**: Press `Cmd+Option+E` on an MQL statement. TablePro converts `find`, `aggregate`, `countDocuments`, update, delete, and `findOneAnd*` calls into `db.runCommand({"explain": ..., "verbosity": "executionStats"})`.

**MQL Shell Queries**: Filters and pipelines are parsed as JSON and Extended JSON, not JavaScript. Quote every key, operators included: `{age: {$gte: 18}}` fails with a parse error. mongosh helpers like `ISODate("2025-01-01")` fail too; write `{"$date": "2025-01-01T00:00:00Z"}`. The editor has no comment syntax, so a `//` line becomes part of the statement.

Find with a filter:

```javascript theme={null}
db.users.find({"age": {"$gte": 18}, "active": true})
```

Find with a projection and a sort:

```javascript theme={null}
db.orders.find(
  {"status": "completed"},
  {"customerId": 1, "total": 1, "date": 1}
).sort({"date": -1}).limit(20)
```

Aggregation pipeline, with dates in Extended JSON:

```javascript theme={null}
db.sales.aggregate([
  {"$match": {"date": {"$gte": {"$date": "2025-01-01T00:00:00Z"}}}},
  {"$group": {"_id": "$product", "totalSales": {"$sum": "$amount"}}},
  {"$sort": {"totalSales": -1}},
  {"$limit": 10}
])
```

Count documents:

```javascript theme={null}
db.users.countDocuments({"role": "admin"})
```

**Supported methods**: collection-level `find`, `findOne`, `aggregate`, `countDocuments`/`count`, `insertOne`/`insertMany`, `updateOne`/`updateMany`, `replaceOne`, `deleteOne`/`deleteMany`, `findOneAndUpdate`/`findOneAndReplace`/`findOneAndDelete`, `createIndex`, `dropIndex`, `drop`; database-level `getCollectionNames`/`listCollections`, `createCollection`, `dropDatabase`, `version`, `stats`. Anything else goes through `db.runCommand({...})` or `db.adminCommand({...})`. Unlisted shell methods (for example `distinct` or `getUsers`) return an unsupported-method error.

## Troubleshooting

**Connection refused**: Check MongoDB is running (`brew services start mongodb-community`), verify host/port in `mongod.conf`, check `bindIp` setting.

**Auth failed**: Verify username, password, auth database, and auth mechanism. The MQL editor does not parse `db.getUsers()` or `db.createUser()`; inspect users with `db.runCommand({"usersInfo": 1})` or manage them in mongosh.

**Timeout**: Verify host/port, check network and firewall, whitelist your IP in MongoDB Atlas.

## Limitations

* Transactions are not exposed. Statements always run standalone, on any topology.
* The grid schema is inferred by sampling documents, not read from a validator.
* GridFS buckets are not browsable.
* Change streams are unsupported.
