首页 文章

CosmosDB - 有没有办法获得MongoDB API RequestCharge

提问于
浏览
2

因此,当针对CosmosDB使用带有C#驱动程序的MongoDB API时,我们能否以某种方式从每个查询的CosmosDB响应中获取 RequestCharge

1 回答

  • 2

    因此,对于任何挣扎于同一事物的人来说,这就是解决方案 .

    Cosmos DB MongoDB API具有专用命令: getLastRequestStatistics

    参考:https://docs.microsoft.com/en-us/azure/cosmos-db/request-units

    因此,在执行实际查询后,应立即触发:

    var result = this._db.RunCommand<BsonDocument>(new BsonDocument{{ "getLastRequestStatistics", 1 }});
    

    这将给Cosmos DB带来实际成本的实际响应 . 响应如下:

    {
    "_t" : "GetRequestStatisticsResponse", 
    "ok" : 1, 
    "CommandName" : "find", 
    "RequestCharge" : 5.5499999999999998, 
    "RequestDurationInMilliSeconds" : NumberLong(25) 
    }
    

相关问题