2
votes

I have a CosmosDB Collection which I'm querying using the REST API.

I'd like to access the total number of documents which match my query. I know I can do a count, but that means two calls, one for the count and a subsequent one to retrieve the actual records.

I would assume this is not possible in a single call, BUT.. the Data Explorer in Azure Portal seems to manage it, so just wondering if anyone has been able to figure out what calls it makes, to get this:

Showing Results 1 - 10 Retrieved document count 342 Retrieved document size 2868425 bytes Output document count 10

It's the Retrieved Document Count I need - if the portal can do it, there ought to be a way :)

I've tried the JAVA SDK as well as REST but can't see any useful options in there either

1
"Retrieved document count" does not have to match real number of documents satisfying the query. It may be higher sometimes. - irriss

1 Answers

2
votes

As so often is the case in this game, asking a question triggers the answer... so apologies in advance.

The answer is to send the x-ms-documentdb-populatequerymetrics header in the request. The response then gives a whole bunch of useful stuff in x-ms-documentdb-query-metrics.

What I would like to understand still is whether this has any performance impact?