简体   繁体   中英

How to get the number of partitions in CosmosDB MongoDB API

In order to tune the performance of a CosmosDB for MongoDB API, I need to get the number of partitions in a collection.

The naive way of doing this would be to query for all distinct values for the partition key, like this (in C#):

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

But of course this would need to look at every single document or at least scan the whole index and fails with Query exceeded the maximum allowed memory usage of 40 MB. Please consider adding more filters to reduce the query response size... Query exceeded the maximum allowed memory usage of 40 MB. Please consider adding more filters to reduce the query response size... .

I have also looked at the PartitionKeyRangeStatistics but that explicitly states If your partition keys are below 1GB of storage, they may not show up in the reported statistics , which applies to most of the partitions.

Any ideas on how to get an accurate count of the partitions in a collection?

在Cosmosdb中使用获取Partition Key Ranges API您可以检索分区键范围列表(物理分区)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM