microsoft/skills

azure-cosmos-rust

在 Rust 中用官方 Cosmos 客户端同时保留 id 与分区键

  • SKILL.md 已保存
  • 中文用法已整理
  • 安装与运行未实测
先判断是否解决你的问题

azure-cosmos-rust 是什么?

azure-cosmos-rust 使用官方azure_data_cosmos crate接入Cosmos DB NoSQL API,覆盖分区文档创建、读取、替换、删除与Patch。它强调官方crate、明确分区键与Rust可用的身份类型,避免混入社区SDK或其他语言API。

中文说明由本站依据来源整理;英文原文保留在页面下方。

按客户端选择安装入口

怎么接入你的 Agent?

  1. 定位完整 Skill 目录

    打开本项目来源,核对 SKILL.md 及其引用的脚本和资料。

  2. 交给你正在用的 Agent

    在下面选择客户端,展开并复制安装指令,让 Agent 读取来源后选择安装方式。

  3. 确认识别,再做具体任务

    让 Agent 回报安装目录和识别到的名称 azure-cosmos-rust,然后按本页使用示例提供材料。

展开并复制给 Codex 的安装指令
发送给 Codex

安装并检查 azure-cosmos-rust

请在 Codex 的当前工作环境中安装并检查 azure-cosmos-rust 这个 Skill。

项目身份:microsoft/skills / azure-cosmos-rust
来源:https://github.com/microsoft/skills/blob/f03ec5392f7a0f3aca12af47477e92f1edf7b44c/.github/plugins/azure-sdk-rust/skills/azure-cosmos-rust/SKILL.md
已定位的源文件:.github/plugins/azure-sdk-rust/skills/azure-cosmos-rust/SKILL.md

1. 先阅读真实 SKILL.md 和它引用的必要文件,确认触发条件、安装方式、依赖与权限;尊重源文件要求的审批步骤。
2. 按当前客户端支持的方式安装完整 Skill 目录,保留已有配置,不只复制一段提示词。涉及缺失凭证、目标目录或权限时先列出缺项并向我确认。
3. 安装后回读实际目录、Skill 名称和识别结果,说明哪些步骤已完成,哪些只是文档检查,不得把安装成功当作任务已经实测。
4. 如来源提供了可安全验证的示例,在我提供所需输入后做一个最小任务;创建、修改、删除、部署或发送内容前,按源文件和我的授权执行。
准备输入,再按步骤执行

装好以后,具体怎么用?

准备哪些材料

  • 准备COSMOS_ENDPOINT、数据库/容器名称、容器分区键路径、读写身份,以及azure_data_cosmos、azure_identity、serde、tokio等实际使用依赖。

会得到什么

  • 使用官方crate的Rust文档操作代码、分区键映射与身份说明。

实际使用顺序

  1. 选择azure-sdk发布的azure_data_cosmos,而非azure_cosmos等社区crate;本地用DeveloperToolsCredential,云端按环境选ManagedIdentityCredential,绑定版本不存在DefaultAzureCredential。
  2. 按实际crate README核对CosmosClient builder、AccountReference、RoutingStrategy签名,再取得database_client与container_client。序列化模型中的分区字段要对应真实容器路径。
  3. 每次item操作同时提供分区键和id,响应通过into_model解析;部分字段修改可用PatchInstructions,替换整个item则用replace_item。额外引入azure_core类型时才添加直接依赖;key认证另启用key_auth特性。
使用示例

从一个具体任务开始

本站根据源文件编写的使用示例,未在本站实际运行。示例中的文件由你提供。

安装并识别 Skill 后发送

复制一个具体任务

教学任务:使用 azure-cosmos-rust,为现有NoSQL容器写一个只读Rust函数,以我提供的partition key和id读取订单并into_model。先检查Cargo依赖与builder签名,不用DefaultAzureCredential,不创建数据库/容器或写入item。
预期结果

预期得到分区参数和模型映射明确的代码;本站未编译或读取Cosmos数据。

使用前先看这些限制

使用条件与边界

  • 同名字段partition_key并不自动匹配容器实际分区路径,需先核对容器定义。
  • 源中客户端层级表与完整builder示例省略程度不同,不能将简写拼接为已编译代码;路由偏好不保证最低延迟。
针对这个 Skill 的疑问

常见问题

为什么不能只给id读取文档?

绑定源的item API要求同时指定分区键。id只在其分区范围内定位文档,错误分区不能简单当作整库不存在该id。

需要核对时再展开原文

来源原文与资料状态

源文件
已保存 SKILL.md,抓取于 2026-11-16T12:36:35.145Z
中文使用说明
已针对下方源文件版本整理用途、用法和常见问题
安装与任务测试
本站未执行安装或任务测试
来源复核
本页中文用法已对照保存版本的完整 SKILL.md 阅读整理
展开 SKILL.md 原文、章节与历史收录资料

.github/plugins/azure-sdk-rust/skills/azure-cosmos-rust/SKILL.md · 抓取时间 2026-11-16T12:36:35.145Z

以下保留源文件的 description、章节及摘录,供核对中文说明;完整文件通过上方链接打开。

抓取成功不代表已完成安装或任务测试。

来源 description(原文)

Azure Cosmos DB library for Rust (NoSQL API). Document CRUD, containers, and globally distributed data. Triggers: "cosmos db rust", "CosmosClient rust", "document crud rust", "NoSQL rust", "partition key rust".

查看源文件章节 / Source sections
  • 原文:Azure Cosmos DB library for Rust
  • 安装 / Installation
  • 原文:Environment Variables
  • 原文:Authentication
  • 原文:Client Hierarchy
  • 原文:Core Workflow
  • 原文:Patch Item
  • 原文:Key Auth (Optional)
  • 原文:RBAC Roles
  • 原文:Best Practices
  • 原文:Reference Links
原文:Azure Cosmos DB library for Rust

Client library for Azure Cosmos DB NoSQL API — document CRUD, containers, and globally distributed data. Use this skill when: - An app needs to store or query documents in Cosmos DB from Rust - You need CRUD operations on items with partition keys - You need key-based auth as an alternative to Entra ID > **IMPORTANT:** Only use the official `azure_data_cosmos` crate published by the [azure-sdk](https://crates.io/users/azure-sdk) crates.io user. Do NOT use the unofficial `azure_cosmos` or `azure_sdk_for_rust` community crates. Official crates use underscores in names and none have version 0.21.0.

安装 / Installation

```sh cargo add azure_data_cosmos azure_identity serde serde_json tokio ``` > If your code uses `azure_core` types directly (for example, `azure_core::credentials::TokenCredential`), add `azure_core` to `Cargo.toml`. If you only use `azure_data_cosmos` re-exports, direct `azure_core` dependency is optional.

原文:Environment Variables

```bash COSMOS_ENDPOINT=https://<account>.documents.azure.com/ # Required for all operations ```

原文:Authentication

Rust Azure SDK code must not use `DefaultAzureCredential`. The Rust identity crate does not provide that type. ```rust use azure_identity::DeveloperToolsCredential; use azure_data_cosmos::{ CosmosClient, AccountReference, AccountEndpoint, RoutingStrategy, }; #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> { // Local dev: DeveloperToolsCredential. Production: use ManagedIdentityCredential. let credential = DeveloperToolsCredential::new(None)?; let endpoint: AccountEndpoint = "https://<account>.documents.azure.com/" .parse()?; let account = AccountReference::with_credential(endpoint, credential); let client = CosmosClient::builder() .build(account, RoutingStrategy::ProximityTo("East US".into())) .await?; Ok(()) } ``` Prefer the crate README/examples when checking builder signatures and CRUD method shapes instead of reconstructing APIs from memory or generated internals.

原文:Client Hierarchy

| Client | Purpose | Access | | ----------------- | ------------------------- | ----------------------------------------------- | | `CosmosClient` | Account-level operations | `CosmosClient::builder().build(account).await?` | | `DatabaseClient` | Database operations | `client.database_client("db")` | | `ContainerClient` | Container/item operations | `database.container_client("c").await` |

原文:Core Workflow

```rust use serde::{Serialize, Deserialize}; use azure_data_cosmos::CosmosClient; #[derive(Serialize, Deserialize)] struct Item { pub id: String, pub partition_key: String, pub value: String, } async fn crud(client: CosmosClient) -> Result<(), Box<dyn std::error::Error>> { let container = client .database_client("myDatabase") .container_client("myContainer") .await; let item = Item { id: "1".into(), partition_key: "pk1".into(), value: "hello".into(), }; // Create container.create_item("pk1", "1", item, None).await?; // Read let resp = container.read_item("pk1", "1", None).await?; let mut item: Item = resp.into_model()?; // Update item.value = "updated".into(); container.replace_item("pk1", "1", item, None).await?; // Delete container.delete_item("pk1", "1", None).await?; Ok(()) } ```

文件 SHA256:1e50ff1d6b290ba30644fb6c501802d0c689b2df0e8ed8aaab14f4f57fa5e4cd

仓库许可证记录:MIT;skill-declaration-captured-not-interpreted,查看来源。

SKILL.md原文description · 2026-11-16T12:36:35.145Z

Azure Cosmos DB library for Rust (NoSQL API). Document CRUD, containers, and globally distributed data. Triggers: "cosmos db rust", "CosmosClient rust", "document crud rust", "NoSQL rust", "partition key rust".

查看历史简介来源

历史收录数据

来源仓库microsoft/skills
Skill源路径.github/plugins/azure-sdk-rust/skills/azure-cosmos-rust/SKILL.md

安装前请让使用的Agent先读取这个SKILL.md及其所在目录,确认依赖和所需权限。此页不生成未经来源验证的安装命令。

返回 Skills 目录,按任务继续筛选 · MCP与Skills教程与资源