Docs Menu
Docs Home
/
MongoDB Manual
/ / /

db.collection.analyzeShardKey()

On this page

  • Definition
  • Syntax
  • Fields
  • Behavior
  • Access Control
  • Output
  • Examples
  • Learn More
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.

db.collection.analyzeShardKey() has this syntax:

db.collection.analyzeShardKey(
{
key: <shardKey>,
keyCharacteristics: <bool>,
readWriteDistribution: <bool>,
sampleRate: <double>,
sampleSize: <int>
}
)
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 true.

readWriteDistribution
boolean
Optional

Whether or not the metrics about the read and write distribution are calculated. For details, see readWriteDistribution.

Defaults to true.

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 sampleRate, you cannot set sampleSize.

Must greater than 0, up to and including 1.

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 sampleSize, you cannot set sampleRate.

If not specified and sampleRate is not specified, the sample size defaults to sample size set by analyzeShardKeyCharacteristicsDefaultSampleSize.

For behavior, see analyzeShardKey Behavior.

For details, see analyzeShardKey Access Control.

For sample output, see analyzeShardKey Output.

For examples, see analyzeShardKey Examples.

Back

Collection Methods