简体   繁体   中英

Get all the Partition Keys in Azure Cosmos DB collection

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.

UPDATE: According to Brian in the comments below, DISTINCT is now supported. Try something like:

SELECT DISTINCT c.partitionKey FROM c

Prior answer...

The only way to get the actual partition key values is to do a unique aggregate on that field. However, there is a relatively easy way to get the partition key ranges. It's not supported directly in any of the SDKs as far as I know, but 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 ranges for the partition keys for each partition. Note, the lower side is inclusive, so you can use that to do your own fan out.

Warning: 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. Either accept this slim risk or code around it.

This functionality is currently not available. However there is a feedback item here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM