---
title: mongodb
page-cloud: true
latest-operator-version: v26.2.6
latest-console-tag: v3.14.0
latest-connect-version: 4.118.0
latest-redpanda-tag: v26.2.7
docname: connect/components/inputs/mongodb
page-component-name: cloud-data-platform
page-version: master
page-component-version: master
page-component-title: Cloud
page-relative-src-path: connect/components/inputs/mongodb.adoc
page-edit-url: https://github.com/redpanda-data/cloud-docs/edit/main/modules/develop/pages/connect/components/inputs/mongodb.adoc
description: Executes a query and creates a message for each document received.
page-context-switcher:
  - name: Input
    to: /cloud-data-platform/develop/connect/components/inputs/mongodb/
  - name: Cache
    to: /cloud-data-platform/develop/connect/components/caches/mongodb/
  - name: Output
    to: /cloud-data-platform/develop/connect/components/outputs/mongodb/
  - name: Processor
    to: /cloud-data-platform/develop/connect/components/processors/mongodb/
page-self-managed-available: "true"
page-self-managed-available-url: https://docs.redpanda.com/connect/components/inputs/mongodb/
page-git-created-date: "2025-06-25"
page-git-modified-date: "2026-10-19"
page-generated-sources:
  - include: connect:components:partial$descriptions/inputs/mongodb.adoc
    generator: null
    version: null
    source: the component specs in https://github.com/redpanda-data/connect
page-generated-content: partial
---

# mongodb

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

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

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

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/cloud-data-platform/develop/connect/components/inputs/sequence/) to execute).

> 📝 **NOTE**
>
> If the service only accepts connections from allowlisted IP addresses, add your cluster’s egress addresses to its allowlist before you deploy the pipeline. On BYOC clusters, see [Allow Pipeline Traffic Through External Firewalls](https://docs.redpanda.com/cloud-data-platform/networking/connect-external-allowlist/) to find the addresses. For Dedicated or Serverless clusters, contact Redpanda support for the addresses.

#### Common

```yml
input:
  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: 0 # No default (optional)
    sort: {} # No default (optional)
    limit: 0 # No default (optional)
```

#### Advanced

```yml
input:
  label: ""
  mongodb:
    url: "" # No default (required)
    database: "" # No default (required)
    username: ""
    password: ""
    app_name: benthos
    aws:
      enabled: false
      region: "" # No default (optional)
      session_duration: 1h
      id: "" # No default (optional)
      secret: "" # No default (optional)
      token: "" # No default (optional)
      role: "" # No default (optional)
      role_external_id: "" # No default (optional)
      roles: [] # No default (optional)
    collection: "" # No default (required)
    operation: find
    json_marshal_mode: canonical
    query: "" # No default (required)
    auto_replay_nacks: true
    batch_size: 0 # No default (optional)
    sort: {} # No default (optional)
    limit: 0 # No default (optional)
```

## Fields

### `app_name`

The client application name.

**Type**: `string`

**Default**: `benthos`

### `auto_replay_nacks`

Whether to automatically replay rejected messages (negative acknowledgements, or nacks) at the output level. If the cause of rejections persists, leaving this option enabled can result in back pressure.

Set `auto_replay_nacks` to `false` to delete rejected messages. Disabling auto replays can greatly improve memory efficiency of high throughput streams, as the original shape of the data is discarded immediately upon consumption and mutation.

**Type**: `bool`

**Default**: `true`

### `aws`

AWS IAM authentication using the `MONGODB-AWS` mechanism, for example against MongoDB Atlas. When enabled, IAM credentials are used instead of a static username and password. Role-derived session credentials are resolved when the component connects and are re-resolved whenever it reconnects. The `mongodb` processor and cache establish their client once at creation and cannot refresh expiring session credentials, so `role`, `roles` and session tokens are rejected for those components; use the ambient credential chain or long-lived access keys with them. For long-running pipelines, prefer the ambient credential chain (leave keys and roles unset), which the driver refreshes automatically.

**Type**: `object`

### `aws.enabled`

Enable AWS IAM authentication using the driver-native `MONGODB-AWS` mechanism. The MongoDB Atlas database user must be created with the AWS IAM authentication type, and connections require TLS. When no static credentials or roles are configured, the ambient AWS credential chain (environment variables, EC2 instance profile, EKS pod role) is used and expiring credentials are refreshed automatically.

**Type**: `bool`

**Default**: `false`

### `aws.id`

The AWS access key ID to authenticate with. When empty, the default AWS credential chain is used.

**Type**: `string`

### `aws.region`

The AWS region used when assuming roles (for STS calls). Only used when `role` or `roles` are configured; the ambient and static-key paths ignore it. If no region is specified then the environment default is used.

**Type**: `string`

### `aws.role`

Optional AWS IAM role ARN to assume for authentication. Cannot be combined with `roles`; use the `roles` array instead when chaining multiple roles.

**Type**: `string`

### `aws.role_external_id`

Optional external ID to use when assuming the role set in `role`. Each entry in `roles` sets its own external ID.

**Type**: `string`

### `aws.roles[]`

Optional array of AWS IAM roles to assume for authentication. Roles are assumed in sequence, each using the credentials of the previous one, enabling chaining for purposes such as cross-account access. Each role can optionally specify an external ID. Cannot be combined with `role`.

**Type**: `array<object>`

### `aws.roles[].role`

AWS IAM role ARN to assume.

**Type**: `string`

**Default**: `""`

### `aws.roles[].role_external_id`

Optional external ID for the role assumption.

**Type**: `string`

**Default**: `""`

### `aws.secret`

The AWS secret access key that pairs with `id`.

> ⚠️ **CAUTION**
>
> This field contains sensitive information that usually shouldn’t be added to a configuration directly. For more information, see [Manage Secrets](https://docs.redpanda.com/cloud-data-platform/develop/connect/configuration/secret-management/) before adding it to your configuration.

**Type**: `string`

### `aws.session_duration`

The duration of the STS session requested when assuming roles. AWS requires at least 15 minutes and caps sessions created through role chaining at one hour. Only used when `role` or `roles` are configured. For long-running pipelines, prefer the ambient credential chain over a fixed session duration, since the driver refreshes ambient credentials automatically as they near expiry.

**Type**: `string`

**Default**: `1h`

### `aws.token`

The AWS session token to use with `id` and `secret`. Required only when using short-term credentials.

**Type**: `string`

### `batch_size`

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

**Type**: `int`

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

### `collection`

The collection to select from.

**Type**: `string`

### `database`

The name of the target MongoDB database.

**Type**: `string`

### `json_marshal_mode`

The json_marshal_mode setting is optional and controls the format of the output message.

**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`

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

**Type**: `int`

### `operation`

The mongodb operation to perform.

**Type**: `string`

**Default**: `find`

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

### `password`

The password to use for authentication. Used together with `username` for basic authentication.

> ⚠️ **CAUTION**
>
> This field contains sensitive information that usually shouldn’t be added to a configuration directly. For more information, see [Manage Secrets](https://docs.redpanda.com/cloud-data-platform/develop/connect/configuration/secret-management/) before adding it to your configuration.

**Type**: `string`

**Default**: `""`

### `query`

Bloblang expression describing MongoDB query.

**Type**: `string`

```yaml
# Examples:
query: |2

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

### `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`

**Type**: `object<int>`

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

# ---

sort:
  age: -1
```

### `url`

The URL of the target MongoDB server.

**Type**: `string`

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

### `username`

The username to connect to the database.

**Type**: `string`

**Default**: `""`