---
title: azure_cosmosdb
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/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/inputs/azure_cosmosdb.adoc
page-edit-url: https://github.com/redpanda-data/cloud-docs/edit/main/modules/develop/pages/connect/components/inputs/azure_cosmosdb.adoc
description: Executes a SQL query against Azure CosmosDB and creates a batch of messages from each page of items.
page-context-switcher:
  - name: Input
    to: /cloud-data-platform/develop/connect/components/inputs/azure_cosmosdb/
  - name: Output
    to: /cloud-data-platform/develop/connect/components/outputs/azure_cosmosdb/
  - name: Processor
    to: /cloud-data-platform/develop/connect/components/processors/azure_cosmosdb/
page-self-managed-available: "true"
page-self-managed-available-url: https://docs.redpanda.com/connect/components/inputs/azure_cosmosdb/
page-git-created-date: "2024-09-09"
page-git-modified-date: "2026-10-19"
page-generated-sources:
  - include: connect:components:partial$descriptions/inputs/azure_cosmosdb.adoc
    generator: null
    version: null
    source: the component specs in https://github.com/redpanda-data/connect
page-generated-content: partial
---

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

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

Executes a SQL query against [Azure CosmosDB](https://learn.microsoft.com/en-us/azure/cosmos-db/introduction) and creates a batch of messages from each page of items.

## Cross-partition queries

Cross-partition queries are currently not supported by the underlying driver. For every query, the PartitionKey values must be known in advance and specified in the config. [See details](https://github.com/Azure/azure-sdk-for-go/issues/18578#issuecomment-1222510989).

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


## Metadata

This component adds the following metadata fields to each message:

-   `activity_id`

-   `request_charge`


You can access these metadata fields using [function interpolation](https://docs.redpanda.com/cloud-data-platform/develop/connect/configuration/interpolation/#bloblang-queries).

### Common

```yml
input:
  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)
    query: "" # No default (required)
    args_mapping: "" # No default (optional)
    auto_replay_nacks: true
```

### Advanced

```yml
input:
  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)
    query: "" # No default (required)
    args_mapping: "" # No default (optional)
    batch_count: -1
    auto_replay_nacks: true
```

## Examples

### Query container

Execute a parametrized SQL query to select documents from a container.

```yaml
input:
  azure_cosmosdb:
    endpoint: http://localhost:8080
    account_key: C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==
    database: blobbase
    container: blobfish
    partition_keys_map: root = "AbyssalPlain"
    query: SELECT * FROM blobfish AS b WHERE b.species = @species
    args_mapping: |
      root = [
          { "Name": "@species", "Value": "smooth-head" },
      ]
```

## Fields

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

### `args_mapping`

A [Bloblang mapping](https://docs.redpanda.com/cloud-data-platform/develop/connect/guides/bloblang/about/) that creates the list of parameters to use with the query. Each parameter is an object with a `Name` field, which matches a named parameter in the query such as `@name`, and a `Value` field. The input evaluates this mapping once, when the input is created, so the mapping cannot reference message contents or metadata.

**Type**: `string`

```yaml
# Examples:
args_mapping: |-
  root = [
    { "Name": "@name", "Value": "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`

### `batch_count`

The maximum number of messages that should be accumulated into each batch. Use '-1' specify dynamic page size.

**Type**: `int`

**Default**: `-1`

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

**Type**: `string`

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

### `database`

Database.

**Type**: `string`

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

### `endpoint`

CosmosDB endpoint.

**Type**: `string`

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

### `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 = now().ts_format("2006-01-02")
```

### `query`

The query to execute

**Type**: `string`

```yaml
# Examples:
query: SELECT c.foo FROM testcontainer AS c WHERE c.bar = "baz" AND c.timestamp < @timestamp
```

## 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`, 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` and use `http://localhost:8080` as the CosmosDB endpoint.