Get all the Partition Keys in Azure Cosmos DB collection

前端 未结 2 898
小鲜肉
小鲜肉 2021-01-04 12:45

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 suitab

相关标签:
2条回答
  • 2021-01-04 13:23

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

    0 讨论(0)
  • 2021-01-04 13:29

    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.

    0 讨论(0)
提交回复
热议问题