2016-10-05 24 views
2

有一些示例代碼可以使用Microsoft.Azure.DocumentDB在azure documentDB中創建集合。但是,我找不到有關如何使用c#使用不同分區模式創建集合的信息。在具有不同分區模式的Azure DocumentDB中創建集合

從門戶網站,有2種模式:單分區和分區。

使用Microsoft.Azure.DocumentDB創建集合時,我們可以使用這個或另一個嗎?

回答

3

您需要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時,您的收藏將是單分區。

+0

只是在Aram的回覆中做了一個小修改 - 我認爲你的意思是當吞吐量設置爲小於10000時,那麼你的集合有單個分區。有關更多詳細信息,請訪問https://github.com/Azure/azure-content/blob/master/articles/documentdb/documentdb-partition-data.md –

相關問題