对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

sh.status()(mongosh方法)

sh.status()

mongos 实例上运行时,打印分片配置的格式化报告以及有关分片集群中现有数据段的信息。如果数据段总数大于或等于 20,则默认行为将禁止显示详细的数据段信息。

The sh.status() method has the following parameter:

Parameter
类型
说明

verbose

布尔

可选。确定详细级别。

如果 true,则该方法将显示:

  • 即使您有 20 个或更多数据段,也可以查看跨分片数据段分布的完整详情以及每个分片上的数据段个数。

  • 活动 mongos 实例的详情。

如果 false,则该方法将显示:

  • 仅当数据段少于 20 个时,才会显示跨分片数据段分布的完整详情。如果有 20 个或更多数据段,该方法会返回 too many chunks to print ... 消息,仅显示每个分片上的数据段个数。

默认的详细值为 false

输出还包括 shardedDataDistribution 部分,其中提供了每个分片集合的数据分布指标。此数据与$shardedDataDistribution聚合阶段的输出相同。

此方法可用于以下环境中托管的部署:

  • MongoDB Atlas:用于云中 MongoDB 部署的完全托管服务

重要

M0 和 Flex 集群不支持此命令。有关更多信息,请参阅不支持的命令。

分片版本部分显示有关配置数据库的信息:

--- Sharding Status ---
sharding version: {
"_id" : <num>,
"minCompatibleVersion" : <num>,
"currentVersion" : <num>,
"clusterId" : <ObjectId>
}

分片部分列出了有关分片的信息。对于每个分片,该部分显示名称、主机和关联的标记(如果有)。

shards:
{ "_id" : <shard name1>, "host" : <string>, "tags" : [ <string> ... ], "state" : <num> }
{ "_id" : <shard name2>, "host" : <string>, "tags" : [ <string> ... ], "state" : <num> }
...

mongos默认下,“活动mongos 实例”部分显示过去60 秒内处于活动状态的 实例的版本和数量信息:

active mongoses:
<version> : <num>

If the method is run with the verbose parameter to true, the Active mongos Instances section displays additional information:

active mongoses:
{ "_id" : "<hostname:port>", "advisoryHostFQDNs" : [ "<name>" ], "mongoVersion" : <string>, "ping" : <ISODate>, "up" : <long>, "waiting" : <boolean> }

自动分割显示有关是否启用自动分割的信息:

autosplit:
Currently enabled: <yes|no>

负载均衡器部分列出有关负载均衡器状态的信息。这可以深入了解当前负载均衡器的操作,在对不均衡的分片集群进行故障排除时非常有用。

balancer:
Currently enabled: yes
Currently running: yes
Collections with active migrations:
config.system.sessions started at Fri May 15 2020 17:38:12 GMT-0400 (EDT)
Failed balancer rounds in last 5 attempts: 0
Migration Results for the last 24 hours:
416 : Success
1 : Failed with error 'aborted', from shardA to shardB

数据库部分列出了有关数据库的信息。它显示数据库名称和每个数据库的主分片

databases:
{ "_id" : <dbname1>, "primary" : <string>, "version": <document> }
{ "_id" : <dbname2>, "primary" : <string>, "version": <document> }
...

分片集合部分提供有关分片的集合的分片详细信息。对于每个分片的集合,该部分显示分片键、每个分片的数据段数量、跨分片的数据段分布 []1 以及分片键范围的标签信息(如果有)。

<dbname>.<collection>
shard key: { <shard key> : <1 or hashed> }
unique: <boolean>
balancing: <boolean>
allowMigrations: <boolean>
chunks:
<shard name1> <number of chunks>
<shard name2> <number of chunks>
...
{ <shard key>: <min range1> } -->> { <shard key> : <max range1> } on : <shard name> <last modified timestamp>
{ <shard key>: <min range2> } -->> { <shard key> : <max range2> } on : <shard name> <last modified timestamp>
...
tag: <tag1> { <shard key> : <min range1> } -->> { <shard key> : <max range1> }
...

The Sharded Data Distribution section displays data distribution information for each sharded collection:

shardedDataDistribution:
[
{
"ns" : "<database>.<collection>",
"shards" : [
{
"shardName" : "<shard name>",
"numOrphanedDocs" : <num>,
"numOwnedDocuments" : <num>,
"ownedSizeBytes" : <num>,
"orphanedSizeBytes" : <num>
}
]
}
]
sh.status.sharding-version._id

The _id is an identifier for the version details.

sh.status.sharding-version.minCompatibleVersion

The minCompatibleVersion is the minimum compatible version of the config server.

在比 6.2 更早的 MongoDB 版本中,该字段包含在 config.version 集合中,但在 mongosh 2.0.0 及更高版本中,该字段不会在 sh.status() 输出中返回。从 MongoDB 6.2 开始,此字段已被删除,并且不会在任何 mongosh 版本或其他客户端应用程序中返回。如要获取版本信息,请参阅特征兼容性版本(fcv)

sh.status.sharding-version.currentVersion

The currentVersion is the current version of the config server.

在比 6.2 更早的 MongoDB 版本中,该字段包含在 config.version 集合中,但在 mongosh 2.0.0 及更高版本中,该字段不会在 sh.status() 输出中返回。从 MongoDB 6.2 开始,此字段已被删除,并且不会在任何 mongosh 版本或其他客户端应用程序中返回。如要获取版本信息,请参阅特征兼容性版本(fcv)

sh.status.sharding-version.clusterId

The clusterId is the identification for the sharded cluster.

sh.status.active-mongoses

如果verbosefalsesh.status.active-mongoses 会列出活动mongos 实例的版本和数量。活动mongos 实例是指在过去mongos 60秒内 ping 通的 个实例。

If verbose is true, sh.status.active-mongoses returns a document for each active mongos instance containing the following fields:

字段
数据类型
说明

_id

字符串

运行 mongos 的主机名和端口。_id 的格式为 <hostname>:<port>

advisoryHostFQDNs

字符串数组

mongos 的完全限定域名(FQDN)的数组。

created

Date

mongos 启动时。

5.2版本新增。

mongoVersion

字符串

正在运行 mongos 的 MongoDB 版本。

ping

Date

mongos 实例每 30 秒向配置服务器发送 ping。该字段表示最后一次 ping 时间。

up

NumberLong

截至上次 ping 时 mongos 已启动的秒数。

waiting

布尔

此字段始终为 true,并且仅为向后兼容而包含。

active mongoses:
{
"_id" : "<hostname:port>",
"advisoryHostFQDNs" : [ "<name>" ],
"created" : <ISODate>,
"mongoVersion" : <string>,
"ping" : <ISODate>,
"up" : <long>,
"waiting" : <boolean>
}
...
sh.status.autosplit

sh.status.autosplit 指示当前是否启用自动分割。

注意

从 MongoDB 6.0.3 开始,不再执行自动数据块分割。这是因为均衡策略的改进。自动分割命令仍然存在,但不执行操作。

在 MongoDB 6.1 以前的版本中:

mongo 方法 sh.enableBalancing(namespace) sh.disableBalancing(namespace) 对自动分割没有影响。

sh.status.automerge

指示是否启用自动合并功能。

注意

只有明确启用或禁用自动合并功能时,才会显示 automerge 部分。默认情况下,自动合并是启用的。

sh.status.shards._id

The _id displays the name of the shard.

sh.status.shards.host

The host displays the host location of the shard.

sh.status.shards.tags

The tags displays all the tags for the shard. The field only displays if the shard has tags.

sh.status.shards.state

The state displays:

  • 0 如果该分片不具备分片感知性。

  • 1 如果该分片具备分片感知性。

注意

从 MongoDB 6.0.3 开始,不再执行自动数据块分割。这是因为均衡策略的改进。自动分割命令仍然存在,但不执行操作。

在 MongoDB 6.1 以前的版本中:

mongo 方法 sh.enableBalancing(namespace) sh.disableBalancing(namespace) 对自动分割没有影响。

sh.status.balancer.currently-enabled

currently-enabled indicates if the balancer is currently enabled on the sharded cluster.

sh.status.balancer.currently-running

currently-running indicates whether the balancer is currently running, and therefore currently balancing the cluster.

sh.status.balancer.collections-with-active-migrations

collections-with-active-migrations lists the names of any collections with active migrations, and specifies when the migration began. If there are no active migrations, this field will not appear in the sh.status() output.

sh.status.balancer.failed-balancer-rounds-in-last-5-attempts

failed-balancer-rounds-in-last-5-attempts displays the number of balancer rounds that failed, from among the last five attempted rounds. A balancer round will fail when a chunk migration fails.

sh.status.balancer.last-reported-error

last-reported-error lists the most recent balancer error message. If there have been no errors, this field will not appear in the sh.status() output.

sh.status.balancer.time-of-reported-error

time-of-reported-error 提供最近所报告错误的日期和时间。

sh.status.balancer.migration-results-for-the-last-24-hours

migration-results-for-the-last-24-hours显示过去24 小时内的迁移次数,以及失败迁移的错误消息。如果最近没有迁移,migration-results-for-the-last-24-hours 将显示No recent migrations

migration-results-for-the-last-24-hours includes all migrations, including those not initiated by the balancer.

sh.status.databases._id

The _id displays the name of the database.

sh.status.databases.primary

The primary displays the primary shard for the database.

sh.status.databases.version

The version displays the version information for the database:

{ "uuid" : UUID("cc250b66-8638-49f7-a2e8-c6f1220b9d7a"), "lastMod" : 1 }

其中:

  • uuid 是数据库标识符。

  • lastMod 是数据库版本。

sh.status.databases.<collection>.shard-key

The shard-key displays the shard key specification document.

sh.status.databases.<collection>.unique

The unique displays whether MongoDB enforces uniqueness on the shard key values (i.e. whether the underlying shard key index is unique).

sh.status.databases.<collection>.balancing

显示负载均衡器是否可以对集合进行负载均衡。 如果负载均衡器已启用并且此状态返回true ,则负载均衡器会在负载均衡操作中包含此集合。 如果状态返回false ,则表示负载均衡器器平衡此集合中的数据。

sh.status.databases.<collection>.allowMigrations

显示是否允许对集合进行迁移。当 true 时,集合允许迁移。当 false 时,集合不允许迁移,从而阻止此集合的数据块迁移。使用 sh.enableMigrations()sh.disableMigrations() 控制此设置。

sh.status.databases.<collection>.chunks

The chunks lists all the shards and the number of chunks that reside on each shard.

sh.status.databases.<collection>.chunk-details

chunk-details列出数据段 []1 的详细信息:

  • 定义该数据段的分片键值的范围,

  • 该数据段所在的分片,以及

  • 该数据段的最后修改时间戳。

sh.status.databases.<collection>.tag

The tag lists the details of the tags associated with a range of shard key values.

sh.status.shardedDataDistribution

一个文档数组,为集群中的每个分片集合提供数据分布指标。该数据与 $shardedDataDistribution 聚合阶段的输出相同。

sh.status.shardedDataDistribution.ns

<database>.<collection> 格式的分片集合的命名空间。

sh.status.shardedDataDistribution.shards

一个报告每个分片的数据分布指标的文档数组。

sh.status.shardedDataDistribution.shards.shardName

分片的名称。

sh.status.shardedDataDistribution.shards.numOrphanedDocs

分片孤立文档的数量。

sh.status.shardedDataDistribution.shards.numOwnedDocuments

分片拥有的文档数量。

sh.status.shardedDataDistribution.shards.ownedSizeBytes

文档未压缩时分分片拥有的文档的估计大小(以字节为单位)。

sh.status.shardedDataDistribution.shards.orphanedSizeBytes

未压缩文档分片孤立文档的估计大小(以字节为单位)。

[1]12 )默认下,如果数据段总数小于 20,分片的集合部分会显示数据块信息。要在有20 个或更多数据段时显示信息,请调用sh.status() verbosetrue方法,并将 参数设立为 ,即sh.status(true)
给本页内容打分