对于 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: The fully managed service for MongoDB deployments in the cloud

重要

This command is not supported in M0 and Flex clusters. For more information, see Unsupported Commands.

The Sharding Version section displays information on the config database:

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

The Shards section lists information on the shard(s). For each shard, the section displays the name, host, and the associated tags, if any.

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

The Active mongos Instances section displays, by default, information on the version and count of mongos instances that have been active within the last 60 seconds:

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>

The Balancer section lists information about the state of the balancer. This provides insight into current balancer operation and can be useful when troubleshooting an unbalanced sharded cluster.

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

The Databases section lists information on the database(s). It displays the database name and the primary shard for each database.

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

The Sharded Collection section provides information on the sharding details for sharded collection(s). For each sharded collection, the section displays the shard key, the number of chunks per shard(s), the distribution of chunks across shards [1], and the tag information, if any, for shard key range(s).

<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

If verbose is false, sh.status.active-mongoses lists the version and count of the active mongos instances. Active mongos instances are mongos instances that have been pinged within the last 60 seconds.

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 displays the number of migrations in the last 24 hours, and the error messages from failed migrations . If there have been no recent migrations, migration-results-for-the-last-24-hours displays 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.partitioned

从 MongoDB 6.0 和特性兼容性版本 (FcV) 6.0 开始,partitioned 标志仅保持与先前版本的向后兼容性。默认情况下,无论 partitioned 值如何,所有数据库都启用分片。

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

The chunk-details lists the details of the chunks [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](1, 2) The sharded collection section, by default, displays the chunk information if the total number of chunks is less than 20. To display the information when you have 20 or more chunks, call the sh.status() methods with the verbose parameter set to true, i.e. sh.status(true).
给本页内容打分