= mongodb
:type: output
:status: experimental
:categories: ["Services"]



////
     THIS FILE IS AUTOGENERATED!

     To make changes, edit the corresponding source file under:

     https://github.com/redpanda-data/connect/tree/main/internal/impl/<provider>.

     And:

     https://github.com/redpanda-data/connect/tree/main/cmd/tools/docs_gen/templates/plugin.adoc.tmpl
////

// © 2024 Redpanda Data Inc.


component_type_dropdown::[]


Inserts items into a MongoDB collection.

Introduced in version 3.43.0.


[tabs]
======
Common::
+
--

```yml
# Common config fields, showing default values
output:
  label: ""
  mongodb:
    url: mongodb://localhost:27017 # No default (required)
    database: "" # No default (required)
    username: ""
    password: ""
    collection: "" # No default (required)
    operation: update-one
    write_concern:
      w: ""
      j: false
      w_timeout: ""
    document_map: ""
    filter_map: ""
    hint_map: ""
    upsert: false
    max_in_flight: 64
    batching:
      count: 0
      byte_size: 0
      period: ""
      check: ""
```

--
Advanced::
+
--

```yml
# All config fields, showing default values
output:
  label: ""
  mongodb:
    url: mongodb://localhost:27017 # No default (required)
    database: "" # No default (required)
    username: ""
    password: ""
    app_name: benthos
    collection: "" # No default (required)
    operation: update-one
    write_concern:
      w: ""
      j: false
      w_timeout: ""
    document_map: ""
    filter_map: ""
    hint_map: ""
    upsert: false
    max_in_flight: 64
    batching:
      count: 0
      byte_size: 0
      period: ""
      check: ""
      processors: [] # No default (optional)
```

--
======


== Performance

This output benefits from sending multiple messages in flight in parallel for improved performance. You can tune the max number of in flight messages (or message batches) with the field `max_in_flight`.

This output benefits from sending messages as a batch for improved performance. Batches can be formed at both the input and output level. You can find out more xref:configuration:batching.adoc[in this doc].

== Fields

=== `url`

The URL of the target MongoDB server.


*Type*: `string`


```yml
# Examples

url: mongodb://localhost:27017
```

=== `database`

The name of the target MongoDB database.


*Type*: `string`


=== `username`

The username to connect to the database.


*Type*: `string`

*Default*: `""`

=== `password`

The password to connect to the database.
[CAUTION]
====
This field contains sensitive information that usually shouldn't be added to a config directly, read our xref:configuration:secrets.adoc[secrets page for more info].
====



*Type*: `string`

*Default*: `""`

=== `app_name`

The client application name.


*Type*: `string`

*Default*: `"benthos"`

=== `collection`

The name of the target collection.
This field supports xref:configuration:interpolation.adoc#bloblang-queries[interpolation functions].


*Type*: `string`


=== `operation`

The mongodb operation to perform.


*Type*: `string`

*Default*: `"update-one"`

Options:
`insert-one`
, `delete-one`
, `delete-many`
, `replace-one`
, `update-one`
.

=== `write_concern`

The write concern settings for the mongo connection.


*Type*: `object`


=== `write_concern.w`

W requests acknowledgement that write operations propagate to the specified number of mongodb instances.


*Type*: `string`

*Default*: `""`

=== `write_concern.j`

J requests acknowledgement from MongoDB that write operations are written to the journal.


*Type*: `bool`

*Default*: `false`

=== `write_concern.w_timeout`

The write concern timeout.


*Type*: `string`

*Default*: `""`

=== `document_map`

A bloblang map representing a document to store within MongoDB, expressed as https://www.mongodb.com/docs/manual/reference/mongodb-extended-json/[extended JSON in canonical form^]. The document map is required for the operations insert-one, replace-one and update-one.


*Type*: `string`

*Default*: `""`

```yml
# Examples

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

=== `filter_map`

A bloblang map representing a filter for a MongoDB command, expressed as https://www.mongodb.com/docs/manual/reference/mongodb-extended-json/[extended JSON in canonical form^]. The filter map is required for all operations except insert-one. It is used to find the document(s) for the operation. For example in a delete-one case, the filter map should have the fields required to locate the document to delete.


*Type*: `string`

*Default*: `""`

```yml
# Examples

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

=== `hint_map`

A bloblang map representing the hint for the MongoDB command, expressed as https://www.mongodb.com/docs/manual/reference/mongodb-extended-json/[extended JSON in canonical form^]. This map is optional and is used with all operations except insert-one. It is used to improve performance of finding the documents in the mongodb.


*Type*: `string`

*Default*: `""`

```yml
# Examples

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

=== `upsert`

The upsert setting is optional and only applies for update-one and replace-one operations. If the filter specified in filter_map matches, the document is updated or replaced accordingly, otherwise it is created.


*Type*: `bool`

*Default*: `false`
Requires version 3.60.0 or newer

=== `max_in_flight`

The maximum number of messages to have in flight at a given time. Increase this to improve throughput.


*Type*: `int`

*Default*: `64`

=== `batching`

Allows you to configure a xref:configuration:batching.adoc[batching policy].


*Type*: `object`


```yml
# Examples

batching:
  byte_size: 5000
  count: 0
  period: 1s

batching:
  count: 10
  period: 1s

batching:
  check: this.contains("END BATCH")
  count: 0
  period: 1m
```

=== `batching.count`

A number of messages at which the batch should be flushed. If `0` disables count based batching.


*Type*: `int`

*Default*: `0`

=== `batching.byte_size`

An amount of bytes at which the batch should be flushed. If `0` disables size based batching.


*Type*: `int`

*Default*: `0`

=== `batching.period`

A period in which an incomplete batch should be flushed regardless of its size.


*Type*: `string`

*Default*: `""`

```yml
# Examples

period: 1s

period: 1m

period: 500ms
```

=== `batching.check`

A xref:guides:bloblang/about.adoc[Bloblang query] that should return a boolean value indicating whether a message should end a batch.


*Type*: `string`

*Default*: `""`

```yml
# Examples

check: this.type == "end_of_transaction"
```

=== `batching.processors`

A list of xref:components:processors/about.adoc[processors] to apply to a batch as it is flushed. This allows you to aggregate and archive the batch however you see fit. Please note that all resulting messages are flushed as a single batch, therefore splitting the batch into smaller batches using these processors is a no-op.


*Type*: `array`


```yml
# Examples

processors:
  - archive:
      format: concatenate

processors:
  - archive:
      format: lines

processors:
  - archive:
      format: json_array
```


