C#:您如何以编程方式扩展现有DocumentDB集合的定价层?

时间:2015-10-01 17:19:18

标签: c# azure scalability azure-cosmosdb

我希望能够在C#中修改现有DocumentDB集合的OfferType(例如,定价等级S2S3等),但我不会这样做。看到Microsoft.Azure.Documents.DocumentCollection类的任何成员都会为此提供便利。

是否有其他方法可以提供此功能?

2 个答案:

答案 0 :(得分:3)

请参阅此代码段,了解如何使用.NET SDK更改DocumentDB集合的性能级别

https://azure.microsoft.com/en-gb/documentation/articles/documentdb-performance-levels/#changing-performance-levels-using-the-net-sdk

// Query the "offers" feed to retrieve the offer for the collection
Offer offer = client.CreateOfferQuery()
                    .Where(r => r.ResourceLink == "collection selfLink")    
                    .AsEnumerable()
                    .SingleOrDefault();

//Change the offer type to S1, S2 or S3
offer.OfferType = "S3";

//Now update the "offer" resource
Offer updated = await client.ReplaceOfferAsync(offer);

答案 1 :(得分:1)

这是V2商品类型的更新示例,提供对DTU的控制和新的每分钟RU标志:

var collectionLink = UriFactory.CreateDocumentCollectionUri("databaseId","collectionName");
var response = await Client.ReadDocumentCollectionAsync(collectionLink);
var collection = response.Resource;

var results = await Client.CreateOfferQuery()
            .Where(o => o.ResourceLink == collection.SelfLink)
            .AsDocumentQuery()
            .ExecuteNextAsync<OfferV2>();

var offer = results.FirstOrDefault();

var updatedOffer = new OfferV2(offer, offerThroughput:800, offerEnableRUPerMinuteThroughput:true);

await Client.ReplaceOfferAsync(updatedOffer);

另见: https://msdn.microsoft.com/en-us/library/microsoft.azure.documents.offerv2.aspx