且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-02-15 10:48:15

您需要拥有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.