Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does SELECT count(1) FROM c change values each time I query it in CosmosDB Document Explorer?

I have a database with about 600-700 thousand documents. When I am in the Document Explorer and I execute "SELECT value count(1) FROM c", it returns values ranging from 64,000 to 72,000, seemingly at random. When I execute this using the Python SDK, it returns the actual count I mentioned above. Why is this?

like image 536
Max Candocia Avatar asked Oct 28 '25 04:10

Max Candocia


1 Answers

The count query is limited by the number for RUs allocated to your collection. The response that you would have received will have a continuation token. You have to keep looking for next set of results and keep on adding it, which will give you the final count. For example, I tried a count query on my Cosmos DB, and these were the results

  1. First execution

    [ { "$1": 184554 } ]

  2. Next set of continuation. (By clicking Next button from Azure portal Data Explorer)

    [ { "$1": 181909 } ]

  3. Next set of continuation. (By clicking Next button from Azure portal Data Explorer)

    [ { "$1": 25589 } ]

So, finally the count is 184554 + 181909 + 25589 = 3,92,052

like image 141
Mayur Dhingra Avatar answered Oct 30 '25 02:10

Mayur Dhingra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!