用于 Azure Cosmos DB 的 Azure CLI 示例Azure CLI samples for Azure Cosmos DB

下表包括用于 Azure Cosmos DB 的示例 Azure CLI 脚本的链接。The following table includes links to sample Azure CLI scripts for Azure Cosmos DB. 使用右侧的链接可导航到 API 特定示例。Use the links on the right to navigate to API specific samples. 常见示例在所有 API 间是相同的。Common samples are the same across all APIs. Azure CLI 参考中收录了所有 Azure Cosmos DB CLI 命令的参考页。Reference pages for all Azure Cosmos DB CLI commands are available in the Azure CLI Reference. 还可以在 Azure Cosmos DB CLI GitHub 存储库中找到 Azure Cosmos DB CLI 脚本示例。Azure Cosmos DB CLI script samples can also be found in the Azure Cosmos DB CLI GitHub Repository.

这些示例要求使用 Azure CLI 2.9.1 版或更高版本。These samples require Azure CLI version 2.9.1 or later. 运行 az --version 即可查找版本。Run az --version to find the version. 如果需要进行安装或升级,请参阅安装 Azure CLIIf you need to install or upgrade, see Install Azure CLI

常见示例Common Samples

这些示例适用于所有 Azure Cosmos DB APIThese samples apply to all Azure Cosmos DB APIs

任务Task 说明Description
添加或故障转移区域Add or failover regions 添加区域、更改故障转移优先级、触发手动故障转移。Add a region, change failover priority, trigger a manual failover.
帐户密钥和连接字符串 Account keys and connection strings  列出帐户密钥、只读密钥,重新生成密钥并列出连接字符串。List account keys, read-only keys, regenerate keys and list connection strings.
使用 IP 防火墙保护Secure with IP firewall 创建配置了 IP 防火墙的 Cosmos 帐户。Create a Cosmos account with IP firewall configured.
使用服务终结点保护新帐户Secure new account with service endpoints 使用服务终结点创建 Cosmos 帐户并确保其安全。Create a Cosmos account and secure with service-endpoints.
使用服务终结点保护现有帐户Secure existing account with service endpoints 最终配置子网后,更新 Cosmos 帐户以使用服务终结点进行保护。Update a Cosmos account to secure with service-endpoints when the subnet is eventually configured.

Core (SQL) API 示例Core (SQL) API Samples

任务Task 说明Description
创建 Azure Cosmos 帐户、数据库和容器Create an Azure Cosmos account, database and container 为 Core (SQL) API 创建 Azure Cosmos DB 帐户、数据库和容器。Creates an Azure Cosmos DB account, database, and container for Core (SQL) API.
创建 Azure Cosmos 帐户、数据库和容器(具有自动缩放功能)Create an Azure Cosmos account, database and container with autoscale 为 Core (SQL) API 创建 Azure Cosmos DB 帐户、数据库和容器(具有自动缩放功能)。Creates an Azure Cosmos DB account, database, and container with autoscale for Core (SQL) API.
更改吞吐量Change throughput 更新数据库和容器的 RU/秒。Update RU/s on a database and container.
锁定资源以防止将其删除Lock resources from deletion 使用资源锁防止删除资源。Prevent resources from being deleted with resource locks.

MongoDB API 示例MongoDB API Samples

任务Task 说明Description
创建 Azure Cosmos 帐户、数据库和集合Create an Azure Cosmos account, database and collection 为 MongoDB API 创建 Azure Cosmos DB 帐户、数据库和集合。Creates an Azure Cosmos DB account, database, and collection for MongoDB API.
创建 Azure Cosmos 帐户、数据库(具有自动缩放功能)以及两个集合(具有共享吞吐量)Create an Azure Cosmos account, database with autoscale and two collections with shared throughput 为 MongoDB API 创建 Azure Cosmos DB 帐户、数据库(具有自动缩放功能)以及两个集合(具有共享吞吐量)。Creates an Azure Cosmos DB account, database with autoscale and two collections with shared throughput for MongoDB API.
更改吞吐量Change throughput 更新数据库和集合的 RU/秒。Update RU/s on a database and collection.
锁定资源以防止将其删除Lock resources from deletion 使用资源锁防止删除资源。Prevent resources from being deleted with resource locks.

Cassandra API 示例Cassandra API Samples

任务Task 说明Description
创建 Azure Cosmos 帐户、密钥空间和表Create an Azure Cosmos account, keyspace and table 为 Cassandra API 创建 Azure Cosmos DB 帐户、密钥空间和表。Creates an Azure Cosmos DB account, keyspace, and table for Cassandra API.
创建 Azure Cosmos 帐户、密钥空间和表(具有自动缩放功能)Create an Azure Cosmos account, keyspace and table with autoscale 为 Cassandra API 创建 Azure Cosmos DB 帐户、密钥空间和表(具有自动缩放功能)。Creates an Azure Cosmos DB account, keyspace, and table with autoscale for Cassandra API.
更改吞吐量Change throughput 更新密钥空间和表的 RU/秒。Update RU/s on a keyspace and table.
锁定资源以防止将其删除Lock resources from deletion 使用资源锁防止删除资源。Prevent resources from being deleted with resource locks.

Gremlin API 示例Gremlin API Samples

任务Task 说明Description
创建 Azure Cosmos 帐户、数据库和图Create an Azure Cosmos account, database and graph 为 Gremlin API 创建 Azure Cosmos DB 帐户、数据库和图。Creates an Azure Cosmos DB account, database, and graph for Gremlin API.
创建 Azure Cosmos 帐户、数据库和图(具有自动缩放功能)Create an Azure Cosmos account, database and graph with autoscale 为 Gremlin API 创建 Azure Cosmos DB 帐户、数据库和图(具有自动缩放功能)。Creates an Azure Cosmos DB account, database, and graph with autoscale for Gremlin API.
更改吞吐量Change throughput 更新数据库和图的 RU/秒。Update RU/s on a database and graph.
锁定资源以防止将其删除Lock resources from deletion 使用资源锁防止删除资源。Prevent resources from being deleted with resource locks.

表 API 示例Table API Samples

任务Task 说明Description
创建 Azure Cosmos 帐户和表Create an Azure Cosmos account and table 为表 API 创建 Azure Cosmos DB 帐户和表。Creates an Azure Cosmos DB account and table for Table API.
创建 Azure Cosmos 帐户和表(具有自动缩放功能)Create an Azure Cosmos account and table with autoscale 为表 API 创建 Azure Cosmos DB 帐户和表(具有自动缩放功能)。Creates an Azure Cosmos DB account and table with autoscale for Table API.
更改吞吐量Change throughput 更新表的 RU/秒。Update RU/s on a table.
锁定资源以防止将其删除Lock resources from deletion 通过资源锁防止资源遭到删除。Prevent resources from being deleted with resource locks.