在C#

时间:2019-09-05 13:30:42

标签: c# .net-core azure-cosmosdb

使用以下command in Azure CLI可以从Cosmos DB数据库读取当前的吞吐量(RU / s):

az cosmosdb sql database throughput show

结果:

{
  "id": null,
  "location": null,
  "name": null,
  "tags": null,
  "throughput": 400,
  "type": null
}

我想在我的.NET Core应用程序中使用此值(吞吐量400)。目前,我引用了Nuget软件包Microsoft.Azure.DocumentDB.Core,并且已经尝试过:

using (var client = new DocumentClient(new Uri("https://MYCOSMOS.documents.azure.com:443/"), "MYKEY"))
{
    var options = new RequestOptions() 
    { 
        PopulateQuotaInfo = true 
    };
    var uri = UriFactory.CreateDocumentCollectionUri("Sample", "orders");
    var result = await client.ReadDocumentCollectionAsync(uri, options);    
}

但是,这仅为我提供了有关文档数量等方面的配额。

1 个答案:

答案 0 :(得分:1)

对于Microsoft.Azure.DocumentDB.Core,您使用的是旧的v.2 SDK,而新的v3 SDK-Microsoft.Azure.Cosmos

已废弃

使用新的SDK,您将执行以下操作:

using (var client = new CosmosClient(new Uri("https://MYCOSMOS.documents.azure.com:443/"), "MYKEY"))
{
   var database = client.GetDatabase("Sample");
   var container = database.GetContainer("orders");

   var databaseThroughput = await database.ReadThroughputAsync();
   var containerThroughput = await container.ReadThroughputAsync();
}