Cloud

mongodb

Performs operations against MongoDB for each message, allowing you to store or retrieve data within message payloads.

  • Common

  • Advanced

processors:
  label: ""
  mongodb:
    url: "" # No default (required)
    database: "" # No default (required)
    username: ""
    password: ""
    collection: "" # No default (required)
    operation: insert-one
    write_concern:
      w: majority
      j: false
      w_timeout: ""
    document_map: ""
    filter_map: ""
    hint_map: ""
    upsert: false
processors:
  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: insert-one
    write_concern:
      w: majority
      j: false
      w_timeout: ""
    document_map: ""
    filter_map: ""
    hint_map: ""
    upsert: false
    json_marshal_mode: canonical

Fields

app_name

The client application name.

Type: string

Default: benthos

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 ID of credentials to use.

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 for the role assumption. Only used with the role field, which cannot be combined with roles.

Type: string

aws.roles[]

Optional array of AWS IAM roles to assume for authentication. Roles can be assumed in sequence, 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 secret for the credentials being used.

This field contains sensitive information that usually shouldn’t be added to a configuration directly. For more information, see Manage Secrets 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 token for the credentials being used, required when using short term credentials.

Type: string

collection

The name of the target collection.

Type: string

database

The name of the target MongoDB database.

Type: string

document_map

A Bloblang map that represents a document to store in MongoDB, expressed as extended JSON in canonical form. The document_map parameter is required for the following database operations: insert-one, replace-one, update-one, and aggregate.

Type: string

Default: ""

# Examples:
document_map: |-
  root.a = this.foo
  root.b = this.bar

filter_map

A Bloblang map that represents a filter for a MongoDB command, expressed as extended JSON in canonical form. The filter_map parameter is required for all database operations except insert-one.

This output uses filter_map to find documents for the specified operation. For example, for a delete-one operation, the filter map should include the fields required to locate the document for deletion.

Type: string

Default: ""

# Examples:
filter_map: |-
  root.a = this.foo
  root.b = this.bar

hint_map

A Bloblang map that represents a hint or index for a MongoDB command to use, expressed as extended JSON in canonical form. This map is optional, and is used with all operations except insert-one.

Define a hint_map to improve performance when finding documents in the MongoDB database.

Type: string

Default: ""

# Examples:
hint_map: |-
  root.a = this.foo
  root.b = this.bar

json_marshal_mode

Controls the format of the output message (optional).

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.

operation

The MongoDB database operation to perform.

Type: string

Default: insert-one

Options: insert-one, delete-one, delete-many, replace-one, update-one, find-one, aggregate

password

The password to use for authentication. Used together with username for basic authentication or with encrypted private keys for secure access.

This field contains sensitive information that usually shouldn’t be added to a configuration directly. For more information, see Manage Secrets before adding it to your configuration.

Type: string

Default: ""

upsert

The upsert parameter is optional, and only applies for update-one and replace-one operations. If the filter specified in filter_map matches an existing document, this operation updates or replaces the document, otherwise a new document is created.

Type: bool

Default: false

url

The URL of the target MongoDB server.

Type: string

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

username

The username required to connect to the database.

Type: string

Default: ""

write_concern

The write concern settings for the MongoDB connection.

Type: object

write_concern.j

The j requests acknowledgement from MongoDB, which is created when write operations are written to the journal.

Type: bool

Default: false

write_concern.w

The w requests acknowledgement, which write operations propagate to the specified number of MongoDB instances.

Type: string

Default: majority

write_concern.w_timeout

The write concern timeout.

Type: string

Default: ""