Srikanth
Srikanth

Reputation: 147

COUNT in documentDB is not working

i am trying to get the number of documents in my collection (country id id partition key)

when i execute the plain query with out partition key as follows it is getting error

SELECT COUNT(c.memberId) FROM c
Error :- Cross partition query only supports 'VALUE ' for aggregates.

late i added partition key in where condition

SELECT COUNT(c.memberId) FROM c where c.countryId=209

when i execute the query every time i am getting different results like

[ { "$1": 39161 } ]

[ { "$1": 400454 } ]

[ { "$1": 300454 } ]

[ { "$1": 200454 } ]

why it is not working properly ? is there any mistake in my query?

Upvotes: 1

Views: 1150

Answers (1)

Mikhail Shilkov
Mikhail Shilkov

Reputation: 35134

When using the Azure Portal's Query Explorer, note that aggregation queries may return the partially aggregated results over a query page. The SDKs will produce a single cumulative value across all pages.

(from docs)

If you are running your queries in the portal, check whether HAS MORE RESULTS is true in the information pane. You'd have to sum up all partial results to get the total count.

Upvotes: 3

Related Questions