在 Azure Cosmos DB Gremlin API 中创建容器Create a container in Azure Cosmos DB Gremlin API

适用于: Gremlin API

本文介绍如何通过不同方式在 Azure Cosmos DB Gremlin API 中创建容器。This article explains the different ways to create a container in Azure Cosmos DB Gremlin API. 它演示了如何使用 Azure 门户、Azure CLI、PowerShell 或受支持的 SDK 来创建容器。It shows how to create a container using Azure portal, Azure CLI, PowerShell, or supported SDKs. 本文演示如何创建容器、指定分区键和预配吞吐量。This article demonstrates how to create a container, specify the partition key, and provision throughput.

本文介绍如何通过不同方式在 Azure Cosmos DB Gremlin API 中创建容器。This article explains the different ways to create a container in Azure Cosmos DB Gremlin API. 如果你使用不同的 API,请参阅适用于 MongoDB 的 APICassandra API表 APISQL API 文章来创建容器。If you are using a different API, see API for MongoDB, Cassandra API, Table API, and SQL API articles to create the container.

备注

创建容器时,请确保不创建名称相同但大小写不同的两个容器。When creating containers, make sure you don't create two containers with the same name but different casing. 这是因为 Azure 平台的某些部分不区分大小写,这可能会对具有此类名称的容器导致遥测和操作混乱/冲突。That's because some parts of the Azure platform are not case-sensitive, and this can result in confusion/collision of telemetry and actions on containers with such names.

使用 Azure 门户进行创建Create using Azure portal

  1. 登录到 Azure 门户Sign in to the Azure portal.

  2. 创建新的 Azure Cosmos 帐户或选择现有的帐户。Create a new Azure Cosmos account, or select an existing account.

  3. 打开“数据资源管理器”窗格,然后选择“新建图形” 。Open the Data Explorer pane, and select New Graph. 接下来,请提供以下详细信息:Next, provide the following details:

    • 表明要创建新数据库还是使用现有数据库。Indicate whether you are creating a new database, or using an existing one.
    • 输入图形 ID。Enter a Graph ID.
    • 对于“无限制”存储容量。Select Unlimited storage capacity.
    • 输入顶点的分区键。Enter a partition key for vertices.
    • 输入要进行预配的吞吐量(例如,1000 RU)。Enter a throughput to be provisioned (for example, 1000 RUs).
    • 选择“确定” 。Select OK.

    Gremlin API 的屏幕截图,突出显示“添加图形”对话框

使用 .NET SDK 创建Create using .NET SDK

如果创建集合时遇到超时异常,请执行读取操作来验证是否已成功创建集合。If you encounter timeout exception when creating a collection, do a read operation to validate if the collection was created successfully. 成功完成集合创建操作之前,读取操作将引发异常。The read operation throws an exception until the collection create operation is successful. 有关创建操作所支持的状态代码列表,请参阅 Azure Cosmos DB 的 HTTP 状态代码一文。For the list of status codes supported by the create operation see the HTTP Status Codes for Azure Cosmos DB article.

// Create a container with a partition key and provision 1000 RU/s throughput.
DocumentCollection myCollection = new DocumentCollection();
myCollection.Id = "myContainerName";
myCollection.PartitionKey.Paths.Add("/myPartitionKey");

await client.CreateDocumentCollectionAsync(
    UriFactory.CreateDatabaseUri("myDatabaseName"),
    myCollection,
    new RequestOptions { OfferThroughput = 1000 });

使用 Azure CLI 创建Create using Azure CLI

使用 Azure CLI 创建 Gremlin 图Create a Gremlin graph with Azure CLI. 有关所有 Azure Cosmos DB API 的所有 Azure CLI 示例的列表,请参阅 Azure Cosmos DB 的 Azure CLI 示例For a listing of all Azure CLI samples across all Azure Cosmos DB APIs see, Azure CLI samples for Azure Cosmos DB.

使用 PowerShell 创建Create using PowerShell

使用 PowerShell 创建 Gremlin 图Create a Gremlin graph with PowerShell. 有关所有 Azure Cosmos DB API 的所有 PowerShell 示例的列表,请参阅 PowerShell 示例For a listing of all PowerShell samples across all Azure Cosmos DB APIs see, PowerShell Samples

后续步骤Next steps