So, when using MongoDB API with C# driver against CosmosDB, can we somehow get RequestCharge
from CosmosDB response for each query?
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.
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.
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.
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.
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)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With