在Azure DocumentDB中创建具有不同分区模式的集合

3

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

从门户中,有两种模式:单个分区和分区。

我们可以在使用Microsoft.Azure.DocumentDB创建集合时使用其中一种吗?

1个回答

7
你需要拥有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 });

注意:
为了创建分区集合,您必须指定每秒请求单位数大于10,000的吞吐量。由于吞吐量是100的倍数,因此必须为10,100或更高。
因此,当您的OfferThroughput设置小于20000时,您的集合将是单分区。

Aram的回答中只有一个小错误需要更正 - 我认为你的意思是当吞吐量设置为小于10000时,你的集合只有一个分区。更多详细信息请参见https://github.com/Azure/azure-content/blob/master/articles/documentdb/documentdb-partition-data.md。 - Shireesh Thota

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接