Azure - CosmosDB
在 Azure CosmosDB NoSQL 容器上执行查询和 CRUD 操作。
对 Azure Cosmos DB(SQL API)容器执行一次操作:参数化 SQL 查询、点读、upsert 或删除,并将结果放在 result 中返回。
连接你的 Azure CosmosDB 账户,自动化数据库操作:运行 SQL 查询、按 ID 读取文档、upsert 记录以及删除条目。
操作:
- Query: 针对容器执行 SQL 查询,可带参数。
- Read: 按 ID 和分区键获取单个文档。
- Upsert: 在容器中创建或更新文档。
- Delete: 按 ID 和分区键删除文档。
工作原理
- 解析节点配置中的表达式。
connection_id、database、container、operation、query、parameters、partitionKey为空时,从输入项的同名字段读取;item只有在配置中至少包含一个键时才使用配置值。operation默认为query。 - 从以下来源获取账户 endpoint 和密钥:写在
connection_id中的AccountEndpoint=…;AccountKey=…;字符串;同格式的connection-string凭据;或包含endpoint与key(或password/accountKey)的basic-auth/object凭据。 - 执行操作:
query使用parameters执行query并读取全部分页;read和delete以item.id和partitionKey(默认取item.id)定位文档;upsert写入item。 - 经
out返回{ result }:query为文档数组,read与upsert为文档本身,delete为{ deleted: true, id }。失败时以{ error }经error返回。
在工作流中
节点在工作流文件(draft_nodes[])中的写法,以及一次成功运行的 envelope。
{
"node_id": "node-open-orders",
"label": "Find open orders",
"operator_slug": "integrations.microsoft.azure.cosmos",
"operator_version": "1.0.0",
"config": {
"connection_id": "pi-credential-xxxx",
"database": "sales",
"container": "orders",
"operation": "query",
"query": "SELECT * FROM c WHERE c.status = @status",
"parameters": [
{
"name": "@status",
"value": "open"
}
]
}
}{
"ok": true,
"data": {
"result": [
{
"id": "ord_123",
"status": "open",
"total": 129.99,
"_rid": "q7x1AKl0VxsBAAAAAAAAAA==",
"_etag": "\"0b00a5c1-0000-0100-0000-6745f2b30000\"",
"_ts": 1764165811
}
]
},
"port": "out"
}配置
-
connection_idstring 必填 -
Azure CosmosDB(SQL API)的凭据。接受 `connection-string`(AccountEndpoint=...;AccountKey=...;)或 `basic-auth`(endpoint + key)类型的凭据。
-
databasestring 必填 支持表达式 -
CosmosDB 数据库名称。
-
containerstring 必填 支持表达式 -
要操作的容器名称。
-
operationstring 可选 -
要执行的数据库操作。
-
querystring 可选 支持表达式 -
针对容器执行的 SQL 查询(例如“SELECT * FROM c WHERE c.status = @status”)。
-
parametersarray 可选 -
用于参数化 SQL 查询的 { name, value } 对象数组。
-
itemobject 可选 支持表达式 -
要 upsert 到容器中的文档对象。
-
partitionKeystring 可选 支持表达式 -
目标文档的分区键值。
代码中的行为
除 schema 描述之外,实现代码对这些键的实际处理。
-
item read和delete会使用它(仅取id),upsert使用整个文档。空对象视为未设置,会改用输入项中的item字段。-
partitionKey upsert会忽略此字段(SDK 从文档中获取分区键)。read和delete默认取item.id,仅当容器按/id分区时才正确。-
parameters - 由
{ "name": "@status", "value": "open" }对象组成的数组,与query中的@占位符对应。
输出端口
out 默认 操作成功。没有匹配结果的查询也从这里输出,result 为 []。
{
"result": [
{
"id": "ord_123",
"status": "open",
"total": 129.99,
"_rid": "q7x1AKl0VxsBAAAAAAAAAA==",
"_etag": "\"0b00a5c1-0000-0100-0000-6745f2b30000\"",
"_ts": 1764165811
}
]
}error 校验、凭据解析或 Cosmos 调用失败。
{
"error": "Query string required for query operation"
}在表达式中
后续节点可通过 $("Azure - CosmosDB").item.json.<路径> 读取此节点输出中的内容(请把 Azure - CosmosDB 换成你的节点标签)。Editor 标记工作流编辑器在 Previous Nodes 中提示的路径(输出契约);Worker 标记 worker 实际通过 out 返回的路径,依据“端口”一节所示的输出。
| 表达式 | Editor | Worker |
|---|---|---|
$("Azure - CosmosDB").item.json.resultCosmos 响应的 Resource 或 FeedResponse |
错误
| 消息 | 端口 | 原因与处理 |
|---|---|---|
connection_id is required | error | 配置和输入项中都没有凭据。 |
Query string required for query operation | error | operation 为 query,但 query 为空。 |
item.id required for <read|delete> | error | read 和 delete 需要带 id 的 item。即使表单只在 upsert 时显示,也请将 item 设为 { "id": "…" }。 |
item object required for upsert | error | 执行 upsert 时未提供文档。 |
Unsupported operation: <operation> | error | operation 不是 query、read、upsert 或 delete。 |
Invalid Cosmos SQL connection string format | error | 连接字符串缺少 AccountEndpoint= 或 AccountKey=。 |
Credential <connection_id> (type '<type>') missing endpoint / key | error | 结构化凭据缺少 endpoint 或密钥。 |
输入契约
-
connection_idstring 必填 -
databasestring 必填 -
containerstring 必填 -
operationstring 可选 -
querystring 可选 -
parametersarray 可选 -
itemobject 可选 -
partitionKeystring 可选
输出契约
-
resultobject 可选 -
Cosmos 响应的 Resource 或 FeedResponse
契约(JSON Schema)
与编排器声明完全一致的定义。All 是完整的 *.definition.js;可与上方各节对照,找出文档与 schema 之间的差异。发布前可用它校验节点。
{
"slug": "integrations.microsoft.azure.cosmos",
"name": "Azure - CosmosDB",
"category": "integrations",
"group": [
{
"key": "microsoft",
"name": "Microsoft",
"icon_url": "/icons/integrations/microsoft/microsoft.svg"
},
{
"key": "azure",
"name": "Azure",
"icon_url": "/icons/integrations/microsoft/azure.svg"
}
],
"icon_url": "/icons/integrations/microsoft/azure-cosmos.svg",
"version": "1.0.0",
"description": "Execute queries and CRUD operations on Azure CosmosDB NoSQL containers.\n\n Connect your Azure CosmosDB account and automate database operations — run SQL queries, read documents by ID, upsert records, and delete items.\n\n **Operations:**\n - **Query:** Execute a SQL query against a container with optional parameters.\n - **Read:** Retrieve a single document by its ID and partition key.\n - **Upsert:** Create or update a document in the container.\n - **Delete:** Remove a document by its ID and partition key.",
"capabilities": [
"nosql",
"database",
"cosmos",
"azure",
"cloud"
],
"config_schema": {
"type": "object",
"properties": {
"connection_id": {
"type": "string",
"title": "CosmosDB Credential",
"description": "Credential for Azure CosmosDB (SQL API). Accepts credentials of type `connection-string` (AccountEndpoint=...;AccountKey=...;) or `basic-auth` (endpoint + key).",
"ui_widget": "connection_picker",
"ui_options": {
"credential_types": [
"connection-string",
"basic-auth"
],
"types": [
"cosmos"
]
}
},
"database": {
"type": "string",
"title": "Database",
"description": "Name of the CosmosDB database.",
"format": "expression"
},
"container": {
"type": "string",
"title": "Container",
"description": "Name of the container to operate on.",
"format": "expression"
},
"operation": {
"type": "string",
"title": "Operation",
"enum": [
"query",
"read",
"upsert",
"delete"
],
"default": "query",
"description": "The database operation to perform."
},
"query": {
"type": "string",
"title": "SQL Query",
"description": "SQL query to execute against the container (e.g., \"SELECT * FROM c WHERE c.status = @status\").",
"format": "expression",
"displayOptions": {
"show": {
"operation": [
"query"
]
}
}
},
"parameters": {
"type": "array",
"title": "Query Parameters",
"description": "Array of { name, value } objects for parameterized SQL queries.",
"displayOptions": {
"show": {
"operation": [
"query"
]
}
}
},
"item": {
"type": "object",
"title": "Document",
"description": "The document object to upsert into the container.",
"format": "expression",
"displayOptions": {
"show": {
"operation": [
"upsert"
]
}
}
},
"partitionKey": {
"type": "string",
"title": "Partition Key",
"description": "Partition key value for the target document.",
"format": "expression",
"displayOptions": {
"show": {
"operation": [
"read",
"upsert",
"delete"
]
}
}
}
},
"required": [
"connection_id",
"database",
"container"
]
},
"input_contract_schema": {
"type": "object",
"properties": {
"connection_id": {
"type": "string"
},
"database": {
"type": "string"
},
"container": {
"type": "string"
},
"operation": {
"type": "string"
},
"query": {
"type": "string"
},
"parameters": {
"type": "array"
},
"item": {
"type": "object"
},
"partitionKey": {
"type": "string"
}
},
"required": [
"connection_id",
"database",
"container"
]
},
"output_contract_schema": {
"type": "object",
"properties": {
"result": {
"type": "object",
"description": "Cosmos response Resource or FeedResponse"
}
}
},
"ports": [
{
"port_id": "out",
"label": "Result",
"description": "Operation result or items",
"is_default": true,
"supports_condition": true
},
{
"port_id": "error",
"label": "Error",
"description": "Error occurred during execution",
"is_default": false,
"supports_condition": false
}
],
"execution_mode": "async",
"required_resources": [],
"compatible_worker_pools": [
"standard-io",
"cloud-io"
],
"tags": [
"nosql",
"azure"
],
"is_stateful": false,
"publisher": {
"identity": "org_sommatic_ai",
"profile": {
"name": "Sommatic AI",
"verified": true,
"url": "https://sommatic.ai",
"logo_url": null
}
}
}{
"type": "object",
"properties": {
"connection_id": {
"type": "string",
"title": "CosmosDB Credential",
"description": "Credential for Azure CosmosDB (SQL API). Accepts credentials of type `connection-string` (AccountEndpoint=...;AccountKey=...;) or `basic-auth` (endpoint + key).",
"ui_widget": "connection_picker",
"ui_options": {
"credential_types": [
"connection-string",
"basic-auth"
],
"types": [
"cosmos"
]
}
},
"database": {
"type": "string",
"title": "Database",
"description": "Name of the CosmosDB database.",
"format": "expression"
},
"container": {
"type": "string",
"title": "Container",
"description": "Name of the container to operate on.",
"format": "expression"
},
"operation": {
"type": "string",
"title": "Operation",
"enum": [
"query",
"read",
"upsert",
"delete"
],
"default": "query",
"description": "The database operation to perform."
},
"query": {
"type": "string",
"title": "SQL Query",
"description": "SQL query to execute against the container (e.g., \"SELECT * FROM c WHERE c.status = @status\").",
"format": "expression",
"displayOptions": {
"show": {
"operation": [
"query"
]
}
}
},
"parameters": {
"type": "array",
"title": "Query Parameters",
"description": "Array of { name, value } objects for parameterized SQL queries.",
"displayOptions": {
"show": {
"operation": [
"query"
]
}
}
},
"item": {
"type": "object",
"title": "Document",
"description": "The document object to upsert into the container.",
"format": "expression",
"displayOptions": {
"show": {
"operation": [
"upsert"
]
}
}
},
"partitionKey": {
"type": "string",
"title": "Partition Key",
"description": "Partition key value for the target document.",
"format": "expression",
"displayOptions": {
"show": {
"operation": [
"read",
"upsert",
"delete"
]
}
}
}
},
"required": [
"connection_id",
"database",
"container"
]
}{
"type": "object",
"properties": {
"connection_id": {
"type": "string"
},
"database": {
"type": "string"
},
"container": {
"type": "string"
},
"operation": {
"type": "string"
},
"query": {
"type": "string"
},
"parameters": {
"type": "array"
},
"item": {
"type": "object"
},
"partitionKey": {
"type": "string"
}
},
"required": [
"connection_id",
"database",
"container"
]
}{
"type": "object",
"properties": {
"result": {
"type": "object",
"description": "Cosmos response Resource or FeedResponse"
}
}
}[
{
"port_id": "out",
"label": "Result",
"description": "Operation result or items",
"is_default": true,
"supports_condition": true
},
{
"port_id": "error",
"label": "Error",
"description": "Error occurred during execution",
"is_default": false,
"supports_condition": false
}
]执行
- 执行方式
async- 有状态
- 否
- 凭据
- 在服务器端根据
connection_id解析,密钥不会进入工作流。 - 能力
nosqldatabasecosmosazurecloud- 标签
nosqlazure
说明与限制
query会将所有分页加载到内存中。对于大型容器,请使用TOP或OFFSET … LIMIT限制数量。read不存在的文档不会失败:SDK 不返回资源,因此节点经out输出且result无值。- 没有
empty端口,worker 也不额外进行重试。
已对照编排器代码核实 · 31e874b · 2026-11-26