【问题标题】:Create Collection in Azure DocumentDB with Different Partition Mode在 Azure DocumentDB 中创建具有不同分区模式的集合
【发布时间】:2016-10-05 22:41:54
【问题描述】:

有一些示例代码使用 Microsoft.Azure.DocumentDB 在 azure documentDB 中创建集合。但是,我找不到有关如何使用 c# 创建具有不同分区模式的集合的信息。

在门户中,有 2 种模式:单分区和分区。

我们可以在使用 Microsoft.Azure.DocumentDB 创建集合时使用一个或另一个吗?

【问题讨论】:

    标签: c# azure azure-cosmosdb


    【解决方案1】:

    您需要有 SDK 版本 1.6.0 或更高版本才能支持文档数据库分区。 使用 SDK,您需要设置 OfferThroughput 值,如下所示。

    在此示例中,我们将/deviceId 设置为分区键。

    DocumentClient client = new DocumentClient(new Uri(endpoint), authKey);
    await client.CreateDatabaseAsync(new Database { Id = "db" });
    
    // Collection for device telemetry. Here the JSON property deviceId will be used as the partition key to 
    // spread across partitions. Configured for 10K RU/s throughput and an indexing policy that supports 
    // sorting against any number or string property.
    DocumentCollection myCollection = new DocumentCollection();
    myCollection.Id = "coll";
    myCollection.PartitionKey.Paths.Add("/deviceId");
    
    await client.CreateDocumentCollectionAsync(
        UriFactory.CreateDatabaseUri("db"),
        myCollection,
        new RequestOptions { OfferThroughput = 20000 });
    

    注意:

    为了创建分区集合,您必须指定throughput 每秒 > 10,000 个请求单位的值。由于吞吐量是 100 的倍数,因此必须为 10,100 或更高。

    因此,当您的 OfferThroughput 设置为小于 20000 时,您的集合将是单分区。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-05
    • 1970-01-01
    • 2017-09-24
    • 1970-01-01
    • 2021-06-01
    • 1970-01-01
    相关资源
    最近更新 更多