Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CosmosDB - Is there a way to get MongoDB API RequestCharge

So, when using MongoDB API with C# driver against CosmosDB, can we somehow get RequestCharge from CosmosDB response for each query?

like image 361
dee zg Avatar asked Oct 28 '17 04:10

dee zg


People also ask

Is Cosmos DB compatible with MongoDB?

The Azure Cosmos DB for MongoDB is compatible with MongoDB server version 3.6 by default for new accounts. The supported operators and any limitations or exceptions are listed below. Any client driver that understands these protocols should be able to connect to Azure Cosmos DB for MongoDB.

How do I extract data from Cosmos DB?

There are a few methods to export data from Cosmos DB. The quickest one is to use Document DB / Cosmos DB Migration Tool. This is a tool provided by Microsoft to migrate data TO/FROM various sources such as MongoDB, JSON, csv and SQL Server to Cosmos DB.

Which APIs are supported by Cosmos DB?

Azure Cosmos DB offers multiple database APIs, which include NoSQL, MongoDB, Cassandra, Gremlin, and Table. By using these APIs, you can model real world data using documents, key-value, graph, and column-family data models.

Is Cosmos DB deprecated?

The support for cosmos DB accounts using Azure storage explorer will be deprecated in future versions that is why you can see deprecated is showing besides cosmos DB accounts option.


1 Answers

So, for anyone struggling with same thing, here is the solution.

Cosmos DB MongoDB API has dedicated command called: getLastRequestStatistics

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

So, immediately after a real query is executed, one should trigger:

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

And that will give actual response from Cosmos DB with real cost. Response looks like:

{
"_t" : "GetRequestStatisticsResponse", 
"ok" : 1, 
"CommandName" : "find", 
"RequestCharge" : 5.5499999999999998, 
"RequestDurationInMilliSeconds" : NumberLong(25) 
}
like image 122
dee zg Avatar answered Oct 03 '22 22:10

dee zg