Docs HomeMongoDB Manual

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.您可以使用configureQueryAnalyzer在集合上配置查询采样。

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描述
keydocumentRequired必要的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. 没有默认值。
keyCharacteristicsbooleanOptional可选的Whether or not the metrics about the characteristics of the shard key are calculated. 是否计算有关分片键特性的度量。For details, see keyCharacteristics.有关详细信息,请参阅keyCharacteristics
Defaults to true. 默认为true
readWriteDistributionbooleanOptional可选的Whether or not the metrics about the read and write distribution are calculated. 是否计算关于读和写分布的度量。For details, see readWriteDistribution.有关详细信息,请参阅readWriteDistribution
Defaults to true. 默认为true
sampleRatedoubleOptional可选的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.如果设置了sampleRate,则无法设置sampleSize
Must greater than 0, up to and including 1.必须大于0,最大值为1(含1)。
There is no default value. 没有默认值。
sampleSizeintegerOptional可选的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.如果设置了sampleSize,则无法设置sampleRate
If not specified and sampleRate is not specified, the sample size defaults to sample size set by analyzeShardKeyCharacteristicsDefaultSampleSize. 如果未指定且未指定sampleRate,则样本大小默认为analyzeShardKeyCharacteristicsDefaultSampleSize设置的样本大小。

Behavior行为

For behavior, see analyzeShardKey Behavior.有关行为,请参阅analyzeShardKey行为

Access Control访问控制

For details, see analyzeShardKey Access Control.有关详细信息,请参阅analyzeShardKey访问控制

Output输出

For sample output, see analyzeShardKey Output.有关示例输出,请参阅analyzeShardKey输出

Examples实例

For examples, see analyzeShardKey Examples.有关示例,请参阅analyzeShardKey示例

Learn More了解更多信息