获取Azure Cosmos DB集合中的所有分区键 [英] Get all the Partition Keys in Azure Cosmos DB collection

查看:101
本文介绍了获取Azure Cosmos DB集合中的所有分区键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始在我们的项目中使用Azure Cosmos DB.出于报告目的,我们需要获取集合中的所有分区密钥.我找不到任何合适的API来实现它.

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.

推荐答案

更新:根据Brian在下面的评论中,现在支持DISTINCT.尝试类似的东西:

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

SELECT DISTINCT c.partitionKey FROM c

先前的答案...

获取实际分区键值的唯一方法是对该字段进行唯一的聚合.但是,有一种相对简单的方法来获取分区键范围.据我所知,任何一个SDK都不直接支持它,但是您可以直接点击https://{your endpoint domain}.documents.azure.com/dbs/{your collection's uri fragment}/pkranges上的REST端点,以拉回每个分区的分区键范围.请注意,下方是包容性的,因此您可以使用它来自己扇出.

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.

警告:pkranges在检索它们的时间和您对它们进行处理的时间之间变化的可能性很小.要么接受这种微小的风险,要么接受围绕它的代码.

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.

这篇关于获取Azure Cosmos DB集合中的所有分区键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆