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.
Navigate to your Azure Cosmos DB account on the Azure portal. Select Keys from the left menu, then select Regenerate Primary Key from the ellipsis on the right of your primary key.
Cosmos DB Partition Keys Overview Partition keys are the core element to distributing your data efficiently into different logical and physical sets so that the queries performed against the database are completed as quickly as possible.
There is no limit to the number of logical partitions in your container. Each logical partition can store up to 20GB of data. Good partition key choices have a wide range of possible values.
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. 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With