db.collection.analyzeShardKey()
Definition
db.collection.analyzeShardKey(key, options)
Calculates metrics for evaluating a shard key for an unsharded or sharded collection. Metrics are based on sampled queries. You can use
configureQueryAnalyzer
to configure query sampling on a collection.
Syntax
db.collection.analyzeShardKey()
has this syntax:
db.collection.analyzeShardKey( { key: <shardKey>, keyCharacteristics: <bool>, readWriteDistribution: <bool>, sampleRate: <double>, sampleSize: <int> } )
Fields
Field | Type | Necessity | Description |
---|---|---|---|
key | document | Required | Shard key to analyze. This can be a candidate shard key for an unsharded collection or sharded collection or the current shard key for a sharded collection. There is no default value. |
keyCharacteristics | boolean | Optional | Whether or not the metrics about the characteristics of the shard key are calculated. For details, see keyCharacteristics. Defaults to |
readWriteDistribution | boolean | Optional | Whether or not the metrics about the read and write distribution are calculated. For details, see readWriteDistribution. Defaults to |
sampleRate | double | Optional | The proportion of the documents in the collection to sample when
calculating the metrics about the characteristics of the shard
key. If you set Must greater than There is no default value. |
sampleSize | integer | Optional | The number of documents to sample when calculating the metrics
about the characteristics of the shard key. If you set
If not specified and |
Behavior
For behavior, see analyzeShardKey Behavior.
Access Control
For details, see analyzeShardKey Access Control.
Output
For sample output, see analyzeShardKey Output.
Examples
For examples, see analyzeShardKey Examples.