获取Azure Cosmos DB集合中的所有分区键

编程入门 行业动态 更新时间:2024-10-23 07:34:30
本文介绍了获取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都不直接支持它,但是您可以直接点击{your endpoint domain}.documents.azure/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 {your endpoint domain}.documents.azure/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集合中的所有分区键

本文发布于:2023-11-29 00:36:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1644592.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:分区   Azure   Cosmos   DB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!