Azure Cosmos DB for MongoDB Tips
Sanity check cost of most used query
Cosmos DB charges based on “request unit” used. So it is useful to check the request unit cost of the most used query. A high cost also often indicates bad performing query, so it really is a lose-lose situation. You most likely want to redesign your query, or add a new index to your table. Here are the steps I took to find out the request unit cost using
mongosh , more info can be found directly from Microsoft: Find request unit charge for Azure Cosmos DB API for MongoDB operations
Be sure to double quote the connection string.
- Run the query in concern:
Sanity check that the output is what you expect.
.toArray()at the end if your query
- Immediately following the query run:
- Repeat the last two steps quickly to make sure you are really looking at the stats of the query you are testing, not another query that came in between the two commands.
RequestChargeis where you’ll find the cost. Typically an efficient query should have the value under 10, and often under 5: