在具有不同分区模式的Azure DocumentDB中创建集合 [英] Create Collection in Azure DocumentDB with Different Partition Mode

查看:47
本文介绍了在具有不同分区模式的Azure DocumentDB中创建集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

There are some sample code that create collection in azure documentDB using Microsoft.Azure.DocumentDB. However, I could not find information about how to create the collection with different partition mode using c#.

在门户网站上,有2种模式:单分区"和分区".

From the portal, there are 2 modes: Single Partition and Partitioned.

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

Can we use one or another when create collection using Microsoft.Azure.DocumentDB?

推荐答案

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

You need to have the SDK Version 1.6.0 or newer to support Document DB Partitioning. Using the SDK you need to set the OfferThroughput value like shown below.

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

In this sample we set the /deviceId as the partition key.

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或更高.

In order to create partitioned collections, you must specify a throughput value of > 10,000 request units per second. Since throughput is in multiples of 100, this has to be 10,100 or higher.

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

So when your OfferThroughput is set to less than 20000 then your collection will be Single Partition.

这篇关于在具有不同分区模式的Azure DocumentDB中创建集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆