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

# MongoDB

> Query documents, run aggregations, and manage collections in MongoDB databases.

The MongoDB connector lets your workflows interact with any MongoDB instance, including MongoDB Atlas, self-hosted clusters, and single-node deployments.

> [!NOTE]
>
> This connector requires a **connection** with valid credentials before it can be used in a workflow. See [Managing Connections](https://docs.condotta.ai/platform/connections.md) for setup instructions.

## Editor experience

Fields that take a MongoDB query, update, or aggregation pipeline (`filter`, `update`, `pipeline`, `command`, `documents`, `projection`, `sort`) render as a JSON editor; paste or type your queries directly without escaping.

Misspelled MongoDB operators are flagged inline with a suggestion. Typing `$grater_than` shows *Did you mean `$gt`?*. Aggregation variables (`$$ROOT`, `$$NOW`) and the positional update marker (`$`) are recognised and never flagged.

## Connection setup

You can connect using either a **connection string** (recommended for Atlas) or **individual credentials**.

**1. Choose your connection method**

**Option A: Connection String** (recommended for MongoDB Atlas):

* Copy the connection string from your Atlas dashboard (e.g., `mongodb+srv://user:pass@cluster.mongodb.net/mydb`)

**Option B: Individual credentials** (for self-hosted or direct connections):

* **Host** (e.g., `localhost` or `mongo.example.com`)
* **Port** (default: `27017`)
* **Username** and **Password**
* **Database** (optional, default database)
* **Auth Source** (optional, authentication database, usually `admin`)

**2. Add the connection in Condotta**

Go to **Connections** in Condotta, click **Add Connection**, select **MongoDB**, and enter either:

* **Connection String**: Your full MongoDB URI, or
* **Host**, **Port**, **Username**, **Password**, **Database**, and **Auth Source** fields

> [!TIP]
>
> **MongoDB Atlas**: Copy the connection string from your cluster's **Connect** dialog. Make sure your IP is in the Atlas network access list.

### Common MongoDB settings

| Provider | Connection method | Notes |
| - | - | - |
| MongoDB Atlas | Connection string (`mongodb+srv://...`) | Add IP to network access list |
| Self-hosted | Host + credentials | Ensure auth is enabled |

## Tools

> [accordion] run-command: Execute a raw database command
>
> Execute any MongoDB database command such as `ping`, `dbStats`, `collStats`, `createUser`, etc.
>
> **command** `object` *required*
>
> MongoDB command object.
>
> **database** `string`
>
> Database to run the command against. Defaults to the connection's database.
>
> **Example request:**
>
> ```json theme={null}
> {
>   "command": { "dbStats": 1 }
> }
> ```
>
> **Example response:**
>
> ```json theme={null}
> {
>   "success": true,
>   "data": {
>     "db": "myapp",
>     "collections": 12,
>     "objects": 45230,
>     "dataSize": 15728640,
>     "ok": 1
>   }
> }
> ```

> [accordion] find-documents: Query documents from a collection
>
> **collection** `string` *required*
>
> Collection name.
>
> **filter** `object`
>
> MongoDB query filter (e.g., `{ "status": "active" }`).
>
> **projection** `object`
>
> Fields to include (1) or exclude (0).
>
> **sort** `object`
>
> Sort order (1 for ascending, -1 for descending).
>
> **limit** `number`
>
> Maximum number of documents to return (default: 100).
>
> **skip** `number`
>
> Number of documents to skip.
>
> **Example request:**
>
> ```json theme={null}
> {
>   "collection": "orders",
>   "filter": { "status": "shipped" },
>   "projection": { "orderId": 1, "total": 1, "customer": 1 },
>   "sort": { "createdAt": -1 },
>   "limit": 5
> }
> ```
>
> **Example response:**
>
> ```json theme={null}
> {
>   "success": true,
>   "data": {
>     "documents": [
>       { "_id": "665a...", "orderId": "ORD-1234", "total": 99.99, "customer": "Alice" },
>       { "_id": "665b...", "orderId": "ORD-1233", "total": 149.50, "customer": "Bob" }
>     ],
>     "count": 2
>   }
> }
> ```

> [accordion] insert-documents: Insert documents into a collection
>
> **collection** `string` *required*
>
> Collection name.
>
> **documents** `object[]` *required*
>
> Array of documents to insert.
>
> **Example request:**
>
> ```json theme={null}
> {
>   "collection": "users",
>   "documents": [
>     { "name": "Alice", "email": "alice@example.com", "role": "admin" },
>     { "name": "Bob", "email": "bob@example.com", "role": "user" }
>   ]
> }
> ```
>
> **Example response:**
>
> ```json theme={null}
> {
>   "success": true,
>   "data": {
>     "insertedCount": 2,
>     "insertedIds": { "0": "665a...", "1": "665b..." }
>   }
> }
> ```

> [accordion] update-documents: Update documents matching a filter
>
> **collection** `string` *required*
>
> Collection name.
>
> **filter** `object` *required*
>
> Query filter to match documents.
>
> **update** `object` *required*
>
> Update operations using MongoDB operators (`$set`, `$inc`, `$push`, etc.).
>
> **upsert** `boolean`
>
> Insert a new document if no match is found (default: false).
>
> **Example request:**
>
> ```json theme={null}
> {
>   "collection": "users",
>   "filter": { "role": "user" },
>   "update": { "$set": { "verified": true } }
> }
> ```
>
> **Example response:**
>
> ```json theme={null}
> {
>   "success": true,
>   "data": {
>     "matchedCount": 42,
>     "modifiedCount": 42,
>     "upsertedCount": 0,
>     "upsertedId": null
>   }
> }
> ```

> [accordion] delete-documents: Delete documents matching a filter
>
> **collection** `string` *required*
>
> Collection name.
>
> **filter** `object` *required*
>
> Query filter to match documents to delete.
>
> **Example request:**
>
> ```json theme={null}
> {
>   "collection": "sessions",
>   "filter": { "expiresAt": { "$lt": "2024-01-01T00:00:00Z" } }
> }
> ```
>
> **Example response:**
>
> ```json theme={null}
> {
>   "success": true,
>   "data": {
>     "deletedCount": 256
>   }
> }
> ```

> [accordion] aggregate: Run an aggregation pipeline
>
> **collection** `string` *required*
>
> Collection name.
>
> **pipeline** `object[]` *required*
>
> Aggregation pipeline stages (`$match`, `$group`, `$sort`, `$project`, `$lookup`, etc.).
>
> **Example request:**
>
> ```json theme={null}
> {
>   "collection": "orders",
>   "pipeline": [
>     { "$match": { "status": "completed" } },
>     { "$group": { "_id": "$customer", "totalSpent": { "$sum": "$total" }, "orderCount": { "$sum": 1 } } },
>     { "$sort": { "totalSpent": -1 } },
>     { "$limit": 10 }
>   ]
> }
> ```
>
> **Example response:**
>
> ```json theme={null}
> {
>   "success": true,
>   "data": {
>     "documents": [
>       { "_id": "Alice", "totalSpent": 1250.00, "orderCount": 12 },
>       { "_id": "Bob", "totalSpent": 980.50, "orderCount": 8 }
>     ],
>     "count": 2
>   }
> }
> ```

> [accordion] list-databases: List all databases
>
> List all databases accessible with the current credentials. No parameters required.
>
> **Example response:**
>
> ```json theme={null}
> {
>   "success": true,
>   "data": {
>     "databases": [
>       { "name": "admin", "sizeOnDisk": 40960 },
>       { "name": "myapp", "sizeOnDisk": 15728640 },
>       { "name": "analytics", "sizeOnDisk": 8388608 }
>     ],
>     "totalSize": 24158208
>   }
> }
> ```

> [accordion] list-collections: List collections in a database
>
> **database** `string`
>
> Database name. Defaults to the connection's database.
>
> **Example response:**
>
> ```json theme={null}
> {
>   "success": true,
>   "data": {
>     "collections": [
>       { "name": "users", "type": "collection" },
>       { "name": "orders", "type": "collection" },
>       { "name": "system.views", "type": "collection" }
>     ]
>   }
> }
> ```

> [accordion] count-documents: Count documents in a collection
>
> **collection** `string` *required*
>
> Collection name.
>
> **filter** `object`
>
> Query filter. Counts all documents if omitted.
>
> **Example request:**
>
> ```json theme={null}
> {
>   "collection": "users",
>   "filter": { "status": "active" }
> }
> ```
>
> **Example response:**
>
> ```json theme={null}
> {
>   "success": true,
>   "data": {
>     "count": 1542
>   }
> }
> ```

> [card] [Try this free for 14 days](https://preview.condotta.ai/signup)
>
> Start a 14-day trial on Band 1. At day 14, choose your band, or stop.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.