# MongoDB (/integrations/mongodb)



{/* MANUAL-CONTENT-START:intro */}

Use [MongoDB](https://www.mongodb.com/) to query collections, insert one or more documents, update or delete documents selected by a filter, and run aggregation pipelines. Configure the database connection and collection for the selected operation.

The `mongodb_query`, `mongodb_insert`, `mongodb_update`, `mongodb_delete`, and `mongodb_execute` operations return data for later workflow steps. Check the write filter and single/multiple-document option before updating or deleting records.

{/* MANUAL-CONTENT-END */}

## Use the block [#usage-instructions]

Find, insert, update, delete, and aggregate data.

## Actions [#actions]

### MongoDB Query [#mongodb-query]

Execute find operation on MongoDB collection

#### Input [#input]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `host` | string | Yes | MongoDB server hostname or IP address |
| `port` | number | Yes | MongoDB server port (default: 27017) |
| `database` | string | Yes | Database name to connect to (e.g., "mydb") |
| `username` | string | No | MongoDB username |
| `password` | string | No | MongoDB password |
| `authSource` | string | No | Authentication database |
| `ssl` | string | No | SSL connection mode (disabled, required, preferred) |
| `collection` | string | Yes | Collection name to query |
| `query` | string | No | MongoDB query filter as JSON string |
| `limit` | number | No | Maximum number of documents to return |
| `sort` | string | No | Sort criteria as JSON string |

#### Output [#output]

| Parameter | Type | Description |
| - | - | - |
| `message` | string | Operation status message |
| `documents` | array | Array of documents returned from the query |
| `documentCount` | number | Number of documents returned |

### MongoDB Insert [#mongodb-insert]

Insert documents into MongoDB collection

#### Input [#input-1]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `host` | string | Yes | MongoDB server hostname or IP address |
| `port` | number | Yes | MongoDB server port (default: 27017) |
| `database` | string | Yes | Database name to connect to (e.g., "mydb") |
| `username` | string | No | MongoDB username |
| `password` | string | No | MongoDB password |
| `authSource` | string | No | Authentication database |
| `ssl` | string | No | SSL connection mode (disabled, required, preferred) |
| `collection` | string | Yes | Collection name to insert into |
| `documents` | array | Yes | Array of documents to insert |

#### Output [#output-1]

| Parameter | Type | Description |
| - | - | - |
| `message` | string | Operation status message |
| `documentCount` | number | Number of documents inserted |
| `insertedId` | string | ID of inserted document (single insert) |
| `insertedIds` | array | Array of inserted document IDs (multiple insert) |

### MongoDB Update [#mongodb-update]

Update documents in MongoDB collection

#### Input [#input-2]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `host` | string | Yes | MongoDB server hostname or IP address |
| `port` | number | Yes | MongoDB server port (default: 27017) |
| `database` | string | Yes | Database name to connect to (e.g., "mydb") |
| `username` | string | No | MongoDB username |
| `password` | string | No | MongoDB password |
| `authSource` | string | No | Authentication database |
| `ssl` | string | No | SSL connection mode (disabled, required, preferred) |
| `collection` | string | Yes | Collection name to update |
| `filter` | string | Yes | Filter criteria as JSON string |
| `update` | string | Yes | Update operations as JSON string |
| `upsert` | boolean | No | Create document if not found |
| `multi` | boolean | No | Update multiple documents |

#### Output [#output-2]

| Parameter | Type | Description |
| - | - | - |
| `message` | string | Operation status message |
| `matchedCount` | number | Number of documents matched by filter |
| `modifiedCount` | number | Number of documents modified |
| `documentCount` | number | Total number of documents affected |
| `insertedId` | string | ID of inserted document (if upsert) |

### MongoDB Delete [#mongodb-delete]

Delete documents from MongoDB collection

#### Input [#input-3]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `host` | string | Yes | MongoDB server hostname or IP address |
| `port` | number | Yes | MongoDB server port (default: 27017) |
| `database` | string | Yes | Database name to connect to (e.g., "mydb") |
| `username` | string | No | MongoDB username |
| `password` | string | No | MongoDB password |
| `authSource` | string | No | Authentication database |
| `ssl` | string | No | SSL connection mode (disabled, required, preferred) |
| `collection` | string | Yes | Collection name to delete from |
| `filter` | string | Yes | Filter criteria as JSON string |
| `multi` | boolean | No | Delete multiple documents |

#### Output [#output-3]

| Parameter | Type | Description |
| - | - | - |
| `message` | string | Operation status message |
| `deletedCount` | number | Number of documents deleted |
| `documentCount` | number | Total number of documents affected |

### MongoDB Execute [#mongodb-execute]

Execute MongoDB aggregation pipeline

#### Input [#input-4]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `host` | string | Yes | MongoDB server hostname or IP address |
| `port` | number | Yes | MongoDB server port (default: 27017) |
| `database` | string | Yes | Database name to connect to (e.g., "mydb") |
| `username` | string | No | MongoDB username |
| `password` | string | No | MongoDB password |
| `authSource` | string | No | Authentication database |
| `ssl` | string | No | SSL connection mode (disabled, required, preferred) |
| `collection` | string | Yes | Collection name to execute pipeline on |
| `pipeline` | string | Yes | Aggregation pipeline as JSON string |

#### Output [#output-4]

| Parameter | Type | Description |
| - | - | - |
| `message` | string | Operation status message |
| `documents` | array | Array of documents returned from aggregation |
| `documentCount` | number | Number of documents returned |

### MongoDB Introspect [#mongodb-introspect]

Introspect MongoDB database to list databases, collections, and indexes

#### Input [#input-5]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `host` | string | Yes | MongoDB server hostname or IP address |
| `port` | number | Yes | MongoDB server port (default: 27017) |
| `database` | string | No | Database name to introspect (e.g., "mydb"). If not provided, lists all databases |
| `username` | string | No | MongoDB username |
| `password` | string | No | MongoDB password |
| `authSource` | string | No | Authentication database |
| `ssl` | string | No | SSL connection mode (disabled, required, preferred) |

#### Output [#output-5]

| Parameter | Type | Description |
| - | - | - |
| `message` | string | Operation status message |
| `databases` | array | Array of database names |
| `collections` | array | Array of collection info with name, type, document count, and indexes |
