# azure_cosmosdb

> 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)

---
title: azure_cosmosdb
latest-operator-version: v26.1.4
latest-console-tag: v3.7.3
latest-connect-version: 4.93.0
latest-redpanda-tag: v26.1.9
docname: connect/components/outputs/azure_cosmosdb
page-component-name: cloud-data-platform
page-version: master
page-component-version: master
page-component-title: Cloud
page-relative-src-path: connect/components/outputs/azure_cosmosdb.adoc
page-edit-url: https://github.com/redpanda-data/cloud-docs/edit/main/modules/develop/pages/connect/components/outputs/azure_cosmosdb.adoc
page-git-created-date: "2024-09-09"
page-git-modified-date: "2026-05-26"
---

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

**Type:** Output ▼

[Output](https://docs.redpanda.com/cloud-data-platform/develop/connect/components/outputs/azure_cosmosdb/)[Input](https://docs.redpanda.com/cloud-data-platform/develop/connect/components/inputs/azure_cosmosdb/)[Processor](https://docs.redpanda.com/cloud-data-platform/develop/connect/components/processors/azure_cosmosdb/)

**Available in:** Cloud, [Self-Managed](https://docs.redpanda.com/connect/components/outputs/azure_cosmosdb/%20%22View%20the%20Self-Managed%20version%20of%20this%20component%22)

Creates or updates messages as JSON documents in [Azure CosmosDB](https://learn.microsoft.com/en-us/azure/cosmos-db/introduction).

#### Common

```yml
outputs:
  label: ""
  azure_cosmosdb:
    endpoint: "" # No default (optional)
    account_key: "" # No default (optional)
    connection_string: "" # No default (optional)
    database: "" # No default (required)
    container: "" # No default (required)
    partition_keys_map: "" # No default (required)
    operation: Create
    item_id: "" # No default (optional)
    batching:
      count: 0
      byte_size: 0
      period: ""
      check: ""
      processors: [] # No default (optional)
    max_in_flight: 64
```

#### Advanced

```yml
outputs:
  label: ""
  azure_cosmosdb:
    endpoint: "" # No default (optional)
    account_key: "" # No default (optional)
    connection_string: "" # No default (optional)
    database: "" # No default (required)
    container: "" # No default (required)
    partition_keys_map: "" # No default (required)
    operation: Create
    patch_operations: [] # No default (optional)
    patch_condition: "" # No default (optional)
    auto_id: true
    item_id: "" # No default (optional)
    batching:
      count: 0
      byte_size: 0
      period: ""
      check: ""
      processors: [] # No default (optional)
    max_in_flight: 64
```

When creating documents, each message must have the `id` property (case-sensitive) set (or use `auto_id: true`). It is the unique name that identifies the document, that is, no two documents share the same `id` within a logical partition. The `id` field must not exceed 255 characters. [See details](https://learn.microsoft.com/en-us/rest/api/cosmos-db/documents).

The `partition_keys` field must resolve to the same value(s) across the entire message batch.

## [](#credentials)Credentials

You can use one of the following authentication mechanisms:

-   Set the `endpoint` field and the `account_key` field

-   Set only the `endpoint` field to use [DefaultAzureCredential](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity#DefaultAzureCredential)

-   Set the `connection_string` field


## [](#batching)Batching

CosmosDB limits the maximum batch size to 100 messages and the payload must not exceed 2MB ([details here](https://learn.microsoft.com/en-us/azure/cosmos-db/concepts-limits#per-request-limits)).

## [](#performance)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 [in this doc](https://docs.redpanda.com/cloud-data-platform/develop/connect/configuration/batching/).

## [](#examples)Examples

### [](#create-documents)Create documents

Create new documents in the `blobfish` container with partition key `/habitat`.

```yaml
output:
  azure_cosmosdb:
    endpoint: http://localhost:8080
    account_key: C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==
    database: blobbase
    container: blobfish
    partition_keys_map: root = json("habitat")
    operation: Create
```

### [](#patch-documents)Patch documents

Execute the Patch operation on documents from the `blobfish` container.

```yaml
output:
  azure_cosmosdb:
    endpoint: http://localhost:8080
    account_key: C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==
    database: testdb
    container: blobfish
    partition_keys_map: root = json("habitat")
    item_id: ${! json("id") }
    operation: Patch
    patch_operations:
      # Add a new /diet field
      - operation: Add
        path: /diet
        value_map: root = json("diet")
      # Remove the first location from the /locations array field
      - operation: Remove
        path: /locations/0
      # Add new location at the end of the /locations array field
      - operation: Add
        path: /locations/-
        value_map: root = "Challenger Deep"
```

## [](#fields)Fields

### [](#account_key)`account_key`

Account key.

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

```yaml
# Examples:
account_key: C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==
```

### [](#auto_id)`auto_id`

Automatically set the item `id` field to a random UUID v4. If the `id` field is already set, then it will not be overwritten. Setting this to `false` can improve performance, since the messages will not have to be parsed.

**Type**: `bool`

**Default**: `true`

### [](#batching-2)`batching`

Allows you to configure a [batching policy](https://docs.redpanda.com/cloud-data-platform/develop/connect/configuration/batching/).

**Type**: `object`

```yaml
# 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-byte_size)`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-check)`batching.check`

A [Bloblang query](https://docs.redpanda.com/cloud-data-platform/develop/connect/guides/bloblang/about/) that should return a boolean value indicating whether a message should end a batch.

**Type**: `string`

**Default**: `""`

```yaml
# Examples:
check: this.type == "end_of_transaction"
```

### [](#batching-count)`batching.count`

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

**Type**: `int`

**Default**: `0`

### [](#batching-period)`batching.period`

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

**Type**: `string`

**Default**: `""`

```yaml
# Examples:
period: 1s

# ---

period: 1m

# ---

period: 500ms
```

### [](#batching-processors)`batching.processors[]`

A list of [processors](https://docs.redpanda.com/cloud-data-platform/develop/connect/components/processors/about/) 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**: `processor`

```yaml
# Examples:
processors:
  - archive:
      format: concatenate

# ---

processors:
  - archive:
      format: lines

# ---

processors:
  - archive:
      format: json_array
```

### [](#connection_string)`connection_string`

Connection string.

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

```yaml
# Examples:
connection_string: AccountEndpoint=https://localhost:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==;
```

### [](#container)`container`

Container.

**Type**: `string`

```yaml
# Examples:
container: testcontainer
```

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

Database.

**Type**: `string`

```yaml
# Examples:
database: testdb
```

### [](#endpoint)`endpoint`

CosmosDB endpoint.

**Type**: `string`

```yaml
# Examples:
endpoint: https://localhost:8081
```

### [](#item_id)`item_id`

ID of item to replace or delete. Only used by the Replace and Delete operations This field supports [interpolation functions](https://docs.redpanda.com/cloud-data-platform/develop/connect/configuration/interpolation/#bloblang-queries).

**Type**: `string`

```yaml
# Examples:
item_id: ${! json("id") }
```

### [](#max_in_flight)`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`

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

Operation.

**Type**: `string`

**Default**: `Create`

| Option | Summary |
| --- | --- |
| Create | Create operation. |
| Delete | Delete operation. |
| Patch | Patch operation. |
| Replace | Replace operation. |
| Upsert | Upsert operation. |

### [](#partition_keys_map)`partition_keys_map`

A [Bloblang mapping](https://docs.redpanda.com/cloud-data-platform/develop/connect/guides/bloblang/about/) which should evaluate to a single partition key value or an array of partition key values of type string, integer or boolean. Currently, hierarchical partition keys are not supported so only one value may be provided.

**Type**: `string`

```yaml
# Examples:
partition_keys_map: root = "blobfish"

# ---

partition_keys_map: root = 41

# ---

partition_keys_map: root = true

# ---

partition_keys_map: root = null

# ---

partition_keys_map: root = json("blobfish").depth
```

### [](#patch_condition)`patch_condition`

Patch operation condition. This field supports [interpolation functions](https://docs.redpanda.com/cloud-data-platform/develop/connect/configuration/interpolation/#bloblang-queries).

**Type**: `string`

```yaml
# Examples:
patch_condition: from c where not is_defined(c.blobfish)
```

### [](#patch_operations)`patch_operations[]`

Patch operations to be performed when `operation: Patch` .

**Type**: `object`

### [](#patch_operations-operation)`patch_operations[].operation`

Operation.

**Type**: `string`

**Default**: `Add`

| Option | Summary |
| --- | --- |
| Add | Add patch operation. |
| Increment | Increment patch operation. |
| Remove | Remove patch operation. |
| Replace | Replace patch operation. |
| Set | Set patch operation. |

### [](#patch_operations-path)`patch_operations[].path`

Path.

**Type**: `string`

```yaml
# Examples:
path: /foo/bar/baz
```

### [](#patch_operations-value_map)`patch_operations[].value_map`

A [Bloblang mapping](https://docs.redpanda.com/cloud-data-platform/develop/connect/guides/bloblang/about/) which should evaluate to a value of any type that is supported by CosmosDB.

**Type**: `string`

```yaml
# Examples:
value_map: root = "blobfish"

# ---

value_map: root = 41

# ---

value_map: root = true

# ---

value_map: root = json("blobfish").depth

# ---

value_map: root = [1, 2, 3]
```

## [](#cosmosdb-emulator)CosmosDB emulator

If you wish to run the CosmosDB emulator that is referenced in the documentation [here](https://learn.microsoft.com/en-us/azure/cosmos-db/linux-emulator), the following Docker command should do the trick:

```bash
> docker run --rm -it -p 8081:8081 --name=cosmosdb -e AZURE_COSMOS_EMULATOR_PARTITION_COUNT=10 -e AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE=false mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator
```

Note: `AZURE_COSMOS_EMULATOR_PARTITION_COUNT` controls the number of partitions that will be supported by the emulator. The bigger the value, the longer it takes for the container to start up.

Additionally, instead of installing the container self-signed certificate which is exposed via `[https://localhost:8081/_explorer/emulator.pem](https://localhost:8081/_explorer/emulator.pem)`, you can run [mitmproxy](https://mitmproxy.org/) like so:

```bash
> mitmproxy -k --mode "reverse:https://localhost:8081"
```

Then you can access the CosmosDB UI via `[http://localhost:8080/_explorer/index.html](http://localhost:8080/_explorer/index.html)` and use `[http://localhost:8080](http://localhost:8080)` as the CosmosDB endpoint.