Reputation: 191
I have recently started using Azure Cosmos DB in our project. For the reporting purpose, we need to get all the Partition Keys in the collection. I could not find any suitable API to achieve it.
Upvotes: 15
Views: 20854
Reputation: 9533
UPDATE: According to Brian in the comments below, DISTINCT
is now supported. Try something like:
SELECT DISTINCT c.partitionKey FROM c
The only way to get the actual partition key values is to do a unique aggregate on that field.
You can directly hit the REST endpoint at https://{your endpoint domain}.documents.azure.com/dbs/{your collection's uri fragment}/pkranges
to pull back the minInclusive
and maxExclusive
ranges for each partition but those are hash space ranges and I don't know how to convert those into partition key values nor do a fanout using the actual minInclusive hash.
Also, there is a slim possibility that the pkranges can change between the time you retrieve them and the time you go to do something with them.
Upvotes: 9