# mongodb

> For the complete documentation index, see [llms.txt](https://docs.redpanda.com/llms.txt). Component-specific: [connect-full.txt](https://docs.redpanda.com/connect-full.txt)

---
title: mongodb
latest-connect-version: 4.93.0
latest-operator-version: v26.1.4
latest-console-tag: v3.7.3
latest-redpanda-tag: v26.1.9
docname: inputs/mongodb
page-component-name: connect
page-version: master
page-component-version: master
page-component-title: Connect
page-relative-src-path: inputs/mongodb.adoc
page-edit-url: https://github.com/redpanda-data/rp-connect-docs/edit/main/modules/components/pages/inputs/mongodb.adoc
page-git-created-date: "2024-05-24"
page-git-modified-date: "2026-05-26"
---

<!-- Source: https://docs.redpanda.com/connect/components/inputs/mongodb.md -->

**Type:** Input ▼

[Input](https://docs.redpanda.com/connect/components/inputs/mongodb/)[Cache](https://docs.redpanda.com/connect/components/caches/mongodb/)[Output](https://docs.redpanda.com/connect/components/outputs/mongodb/)[Processor](https://docs.redpanda.com/connect/components/processors/mongodb/)

**Available in:** [Cloud](https://docs.redpanda.com/cloud-data-platform/develop/connect/components/inputs/mongodb/%20%22View%20the%20Cloud%20version%20of%20this%20component%22), Self-Managed

Executes a query and creates a message for each document received.

Introduced in version 3.64.0.

#### Common

```yml
inputs:
  label: ""
  mongodb:
    url: "" # No default (required)
    database: "" # No default (required)
    username: ""
    password: ""
    collection: "" # No default (required)
    query: "" # No default (required)
    auto_replay_nacks: true
    batch_size: "" # No default (optional)
    sort: "" # No default (optional)
    limit: "" # No default (optional)
```

#### Advanced

```yml
inputs:
  label: ""
  mongodb:
    url: "" # No default (required)
    database: "" # No default (required)
    username: ""
    password: ""
    app_name: benthos
    collection: "" # No default (required)
    operation: find
    json_marshal_mode: canonical
    query: "" # No default (required)
    auto_replay_nacks: true
    batch_size: "" # No default (optional)
    sort: "" # No default (optional)
    limit: "" # No default (optional)
```

Once the documents from the query are exhausted, this input shuts down, allowing the pipeline to gracefully terminate (or the next input in a [sequence](https://docs.redpanda.com/connect/components/inputs/sequence/) to execute).

## [](#fields)Fields

### [](#app_name)`app_name`

The client application name.

**Type**: `string`

**Default**: `benthos`

### [](#auto_replay_nacks)`auto_replay_nacks`

Whether messages that are rejected (nacked) at the output level should be automatically replayed indefinitely, eventually resulting in back pressure if the cause of the rejections is persistent. If set to `false` these messages will instead be deleted. Disabling auto replays can greatly improve memory efficiency of high throughput streams as the original shape of the data can be discarded immediately upon consumption and mutation.

**Type**: `bool`

**Default**: `true`

### [](#batch_size)`batch_size`

A explicit number of documents to batch up before flushing them for processing. Must be greater than `0`. Operations: `find`, `aggregate`

Requires version 4.26.0 or later.

**Type**: `int`

```yaml
# Examples:
batch_size: 1000
```

### [](#collection)`collection`

The collection to select from.

**Type**: `string`

### [](#database)`database`

The name of the target MongoDB database.

**Type**: `string`

### [](#json_marshal_mode)`json_marshal_mode`

The json\_marshal\_mode setting is optional and controls the format of the output message.

Requires version 4.7.0 or later.

**Type**: `string`

**Default**: `canonical`

| Option | Summary |
| --- | --- |
| canonical | A string format that emphasizes type preservation at the expense of readability and interoperability. That is, conversion from canonical to BSON will generally preserve type information except in certain specific cases. |
| relaxed | A string format that emphasizes readability and interoperability at the expense of type preservation.That is, conversion from relaxed format to BSON can lose type information. |

### [](#limit)`limit`

An explicit maximum number of documents to return. Operations: `find`

Requires version 4.26.0 or later.

**Type**: `int`

### [](#operation)`operation`

The mongodb operation to perform.

Requires version 4.2.0 or later.

**Type**: `string`

**Default**: `find`

**Options**: `find`, `aggregate`

### [](#password)`password`

The password to connect to the database.

> ⚠️ **CAUTION**
>
> This field contains sensitive information that usually shouldn’t be added to a configuration directly. For more information, see [Secrets](https://docs.redpanda.com/connect/configuration/secrets/).

**Type**: `string`

**Default**: `""`

### [](#query)`query`

Bloblang expression describing MongoDB query.

**Type**: `string`

```yaml
# Examples:
query: |-

    root.from = {"$lte": timestamp_unix()}
    root.to = {"$gte": timestamp_unix()}
```

### [](#sort)`sort`

An object specifying fields to sort by, and the respective sort order (`1` ascending, `-1` descending). Note: The driver currently appears to support only one sorting key. Operations: `find`

Requires version 4.26.0 or later.

**Type**: `int`

```yaml
# Examples:
sort:
  name: 1

# ---

sort:
  age: -1
```

### [](#url)`url`

The URL of the target MongoDB server.

**Type**: `string`

```yaml
# Examples:
url: mongodb://localhost:27017
```

### [](#username)`username`

The username to connect to the database.

**Type**: `string`

**Default**: `""`