首页 > 解决方案 > 如何在 CosmosDB MongoDB API 中获取分区数

问题描述

为了调整 CosmosDB for MongoDB API 的性能,我需要获取集合中的分区数。

这样做的天真方法是查询分区键的所有不同值,如下所示(在 C# 中):

var results = await SomeCollection.Distinct<string>("PartitionKey", filter: "{}").ToListAsync();

但当然,这需要查看每一个文档,或者至少扫描整个索引并以Query exceeded the maximum allowed memory usage of 40 MB. Please consider adding more filters to reduce the query response size....

我还查看了PartitionKeyRangeStatistics但明确指出If your partition keys are below 1GB of storage, they may not show up in the reported statistics,这适用于大多数分区。

关于如何获得集合中分区的准确计数的任何想法?

标签: c#azureazure-cosmosdb

解决方案


在 Cosmosdb 中使用 Get Partition Key RangesAPI 可以检索分区键范围列表(物理分区)


推荐阅读