Mike
Mike

Reputation: 1738

DocumentDB COUNT Inconsistent Results

I have been trying some queries using the COUNT aggregate in DocumentDB that was just recently released. Even when I run the exact same query multiple times, I am regularly getting different results. I know my data isn't changing. Is there a bug with the aggregate functions, could I be reaching my RU limit and it is only returning the counts that fit within my RU amount, or is something else going on?

My query looks like:

Select COUNT(c.id) FROM c WHERE Array_Contains(c.Property, "SomethingIAmSearchingFor")

My collection contains about 12k documents that are very small (3 or 4 string properties each and one array with less than 10 string items in it)

Upvotes: 2

Views: 806

Answers (1)

Aravind Krishna R.
Aravind Krishna R.

Reputation: 8003

In DocumentDB, aggregate functions are distributed across 1-N partitions, and within each partition executed in chunks/pages based on the available RU like guessed. The SDK fetches the partial aggregates and returns the final results (e.g. sums over the counts from each result).

If you run the query to completion, you will always get the same aggregate result even if the individual partial executions return different results.

In the portal use the "Load more →" link to get the count of the next portion. You need to manually record the counts shown so far and sum them to get the final aggregated count.

Upvotes: 6

Related Questions