# MongoDB

NoSQL document database

- Category: Databases
- Runs in: the Phloem cloud

Lets you and Hamming read documents from a MongoDB database, with each collection's fields listed in Trace.

## What Phloem reads
- The database's collections, with field names and types taken from the first 100 documents of each, listed in Trace
- Collections named `system.*` are left out

Phloem only reads. It never writes to MongoDB.

## What you need
- The server's host, port (default 27017) and database, or a full connection string such as `mongodb+srv://…`
- A user that can read the database, unless the server has no authentication
- Network access from Phloem's cloud to the server

## Connect
1. In the console, open **Connectors**, choose **Add connector**, then **MongoDB**.
2. Enter a **Display Name**.
3. Under **Authentication Method**, choose:
   - **Username & Password** — **Host**, **Port**, **Database**, **Username** and **Password**. **Auth Source** is the authentication database (default `admin`). Set **Replica Set** if you connect to one.
   - **Connection String** — paste the full URI.
4. Choose **Test Connection** (it shows the server version), then **Create Connection**.

## What Hamming can do
- Run find queries with JSON that you or Hamming write: `{"collection": "users", "filter": {"age": {"$gt": 25}}, "limit": 100}`, with an optional `projection`

## Notes
- A query returns 100 documents unless it sets `limit`.
- Aggregation pipelines are not supported. Queries are `find` with a filter.

## Connection fields

| Field | Type | Required | Notes |
|---|---|---|---|
| Host | Text | No |  |
| Port | Number | No |  |
| Database | Text | No |  |
| Username | Text | No |  |
| Password | Secret | No |  |
| Auth Source | Text | No | Authentication database |
| Replica Set | Text | No | Replica set name (optional) |
| Connection String | Text | No | Full MongoDB connection URI |
