> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hellocobi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# MongoDB

> Connect a MongoDB database to Cobi

## Connecting to MongoDB Atlas

MongoDB Atlas uses SRV connection strings. Enter your Atlas cluster hostname (e.g. `cluster0.abc123.mongodb.net`) as the host. Cobi detects the SRV pattern automatically and handles the port for you.

## Connecting to a Self-Hosted MongoDB

Enter your server's hostname or IP address and port (`27017` by default).

## Schema Conventions

Cobi maps MongoDB collections to SQL tables. Keep the following in mind when chatting with the Data Assistant:

| Convention        | Detail                                                                              |
| ----------------- | ----------------------------------------------------------------------------------- |
| **Collections**   | Each collection appears as a table                                                  |
| **`_id` field**   | Present on every document as a unique identifier, used as the primary key           |
| **Nested fields** | Flattened with underscores, so `address.city` becomes `address_city`                |
| **Arrays**        | Array fields are queryable. Ask the Data Assistant to expand or filter them         |
| **Relationships** | MongoDB has no foreign keys. Reference related collections by matching field values |

## Create a Read-Only User

**Self-hosted MongoDB:** run the following in `mongosh`:

```js theme={null}
use admin
db.createUser({
  user: "cobi_reader",
  pwd: "secure_password",
  roles: [{ role: "read", db: "your_database" }]
})
```

**MongoDB Atlas:** create the user in the Atlas UI under **Database Access**, with the built-in `read` role scoped to your database.

## Troubleshooting

See the [Troubleshooting](/platform/data-connectors/troubleshooting) page for help with connection issues.
