Definition定义
db.collection.getShardDistribution()-
Important
mongosh
Method方法This page documents a本页记录了一种mongoshmethod. This is not the documentation for a language-specific driver, such as Node.js.mongosh方法。这不是针对特定语言驱动程序(如Node.js)的文档。For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.有关MongoDB API驱动程序,请参阅特定语言的MongoDB驱动程序文档。Prints the data distribution statistics for a sharded collection.打印分片集合的数据分布统计信息。
Compatibility兼容性
This method is available in deployments hosted in the following environments:此方法在以下环境中托管的部署中可用:
- MongoDB Atlas
: The fully managed service for MongoDB deployments in the cloud:云中MongoDB部署的完全托管服务
Important
This command is not supported in M0 and Flex clusters. For more information, see Unsupported Commands.M0和Flex集群不支持此命令。有关详细信息,请参阅不支持的命令。
- MongoDB Enterprise
: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本 - MongoDB Community
: The source-available, free-to-use, and self-managed version of MongoDB:MongoDB的源代码可用、免费使用和自我管理版本
Syntax语法
The getShardDistribution() method has the following form:getShardDistribution()方法具有以下形式:
db.collection.getShardDistribution()Output输出
Note
The behavior of MongoDB Shell 2.3.3版本中getShardDistribution() changed in MongoDB Shell version 2.3.3:getShardDistribution()的行为发生了变化:
Starting in MongoDB Shell version 2.3.3,从MongoDB Shell 2.3.3版本开始,getShardDistribution()only contains regular sharded data and does not account for orphaned documents.getShardDistribution()只包含常规分片数据,不考虑孤立文档。Prior to MongoDB Shell version 2.3.3,在MongoDB Shell 2.3.3版本之前,getShardDistribution()accounts for both regular sharded data and orphaned documents pending deletion.getShardDistribution()既可以处理常规分片数据,也可以处理待删除的孤立文档。If the collection contains orphaned documents,如果集合包含孤立文档,即使集合在常规数据方面是平衡的,getShardDistribution()might indicate that the collection is unbalanced even if the collection is balanced in terms of regular data.getShardDistribution()也可能表示集合是不平衡的。The shard containing orphaned data has more documents and greater data size, but the same number of chunks compared to other shards.包含孤立数据的分片具有更多的文档和更大的数据大小,但与其他分片相比,块的数量相同。
Sample Output示例输出
The following is a sample output for the distribution of a sharded collection:以下是分片集合分发的示例输出:
Shard shard01 at shard01/localhost:27018
{
data: '38.14MB',
docs: 1000003,
chunks: 2,
'estimated data per chunk': '19.07B',
'estimated docs per chunk': 500001
}
---
Shard shard02 at shard02/localhost:27019
{
data: '38.14B',
docs: 999999,
chunks: 3,
'estimated data per chunk': '12.71B',
'estimated docs per chunk': 333333
}
---
Totals
{
data: '76.29B',
docs: 2000002,
chunks: 5,
'Shard shard01': [ '50 % data', '50 % docs in cluster', '40B avg obj size on shard' ],
'Shard shard02': [ '49.99 % data', '49.99 % docs in cluster', '40B avg obj size on shard' ]
}Output Fields输出字段
Shard shard01 at <host-a> {
data: <size-a>,
docs: <count-a>,
chunks: <number of chunks-a>,
'estimated data per chunk': <size-a>/<number of chunks-a>,
'estimated docs per chunk': <count-a>/<number of chunks-a>
}
---
Shard shard02 at <host-b>
{
data: <size-b>,
docs: <count-b>,
chunks: <number of chunks-b>,
'estimated data per chunk': <size-b>/<number of chunks-b>,
'estimated docs per chunk': <count-b>/<number of chunks-b>
}
---
Totals
{
data: <stats.size>,
docs: <stats.count>,
chunks: <calc total chunks>,
Shard shard01: [ <estDataPercent-a> % data, <estDocPercent-a> % docs in cluster, stats.shards[ <shard-a> ].avgObjSize avg obj size on shard ],
Shard shard02: [ <estDataPercent-b> % data, <estDocPercent-b> % docs in cluster, stats.shards[ <shard-b> ].avgObjSize avg obj size on shard ]
}
The output information displays:输出信息显示:
<shard-x> | |
<host-x> | |
<size-x> | b, Mb).b、Mb)。 |
<count-x> | |
<number of chunks-x> | |
<size-x>/<number of chunks-x> | b, Mb).b、Mb)。 |
<count-x>/<number of chunks-x> | |
<stats.size> | |
<stats.count> | |
<calc total chunks> |
|
<estDataPercent-x> |
|
<estDocPercent-x> |
|
stats.shards[ <shard-x> ].avgObjSize |
Behavior行为
After an unclean shutdown of a 使用Wired Tiger存储引擎不干净地关闭mongod using the Wired Tiger storage engine, count and size statistics reported by db.collection.getShardDistribution() may be inaccurate.mongod后,db.collection.getShardDistribution()报告的计数和大小统计数据可能不准确。
The amount of drift depends on the number of insert, update, or delete operations performed between the last checkpoint and the unclean shutdown. 漂移量取决于在最后一个检查点和不干净关闭之间执行的插入、更新或删除操作的数量。Checkpoints usually occur every 60 seconds. However, 检查点通常每60秒出现一次。然而,使用非默认的mongod instances running with non-default --syncdelay settings may have more or less frequent checkpoints.--syncdelay设置运行的mongod实例可能或多或少地具有检查点。
Run 在validate on each collection on the mongod to restore statistics after an unclean shutdown.mongod上的每个集合上运行validate,以在不干净关闭后恢复统计数据。
After an unclean shutdown:不干净停机后: