2
有一些示例代码可以使用Microsoft.Azure.DocumentDB在azure documentDB中创建集合。但是,我找不到有关如何使用c#使用不同分区模式创建集合的信息。在具有不同分区模式的Azure DocumentDB中创建集合
从门户网站,有2种模式:单分区和分区。
使用Microsoft.Azure.DocumentDB创建集合时,我们可以使用这个或另一个吗?
有一些示例代码可以使用Microsoft.Azure.DocumentDB在azure documentDB中创建集合。但是,我找不到有关如何使用c#使用不同分区模式创建集合的信息。在具有不同分区模式的Azure DocumentDB中创建集合
从门户网站,有2种模式:单分区和分区。
使用Microsoft.Azure.DocumentDB创建集合时,我们可以使用这个或另一个吗?
您需要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请求单位的throughput
值。由于吞吐量是100的倍数,所以它必须是10,100或更高。
因此,当您的OfferThroughput
设置为小于20000时,您的收藏将是单分区。
只是在Aram的回复中做了一个小修改 - 我认为你的意思是当吞吐量设置为小于10000时,那么你的集合有单个分区。有关更多详细信息,请访问https://github.com/Azure/azure-content/blob/master/articles/documentdb/documentdb-partition-data.md –