Sdílet prostřednictvím


DocumentCollection.PartitionKeyRangeStatistics Property

Definition

Gets a collection of PartitionKeyRangeStatistics object in the Azure Cosmos DB service.

[Newtonsoft.Json.JsonIgnore]
public System.Collections.Generic.IReadOnlyList<Microsoft.Azure.Documents.PartitionKeyRangeStatistics> PartitionKeyRangeStatistics { get; }
[<Newtonsoft.Json.JsonIgnore>]
member this.PartitionKeyRangeStatistics : System.Collections.Generic.IReadOnlyList<Microsoft.Azure.Documents.PartitionKeyRangeStatistics>
Public ReadOnly Property PartitionKeyRangeStatistics As IReadOnlyList(Of PartitionKeyRangeStatistics)

Property Value

PartitionKeyRangeStatistics object.

Attributes
Newtonsoft.Json.JsonIgnoreAttribute

Examples

The following code shows how to log statistics for all partition key ranges as a string:

var collection = await client.ReadDocumentCollectionAsync(
    collectionUri,
    new RequestOptions { PopulatePartitionKeyRangeStatistics = true } );

Console.WriteLine(collection.PartitionKeyRangeStatistics.ToString());

To log individual partition key range statistics, use the following code:

var collection = await client.ReadDocumentCollectionAsync(
    collectionUri,
    new RequestOptions { PopulatePartitionKeyRangeStatistics = true } );

foreach(var partitionKeyRangeStatistics in collection.PartitionKeyRangeStatistics)
{
    Console.WriteLine(partitionKeyRangeStatistics.PartitionKeyRangeId);
    Console.WriteLine(partitionKeyRangeStatistics.DocumentCount);
    Console.WriteLine(partitionKeyRangeStatistics.SizeInKB);

    foreach(var partitionKeyStatistics in partitionKeyRangeStatistics.PartitionKeyStatistics)
    {
        Console.WriteLine(partitionKeyStatistics.PartitionKey);
        Console.WriteLine(partitionKeyStatistics.SizeInKB);
    }
 }

The output will look something like that: "statistics": [ {"id":"0","sizeInKB":1410184,"documentCount":42807,"partitionKeys":[]}, {"id":"1","sizeInKB":3803113,"documentCount":150530,"partitionKeys":[{"partitionKey":["4009696"],"sizeInKB":3731654}]}, {"id":"2","sizeInKB":1447855,"documentCount":59056,"partitionKeys":[{"partitionKey":["4009633"],"sizeInKB":2861210},{"partitionKey":["4004207"],"sizeInKB":2293163}]}, {"id":"3","sizeInKB":1026254,"documentCount":44241,"partitionKeys":[]}, {"id":"4","sizeInKB":3250973,"documentCount":124959,"partitionKeys":[]} ]

Remarks

This is reported based on a sub-sampling of partition keys within the collection and hence these are approximate. If your partition keys are below 1GB of storage, they may not show up in the reported statistics.

Applies to

See also