sh.status()
Definition
sh.status()When run on a
mongosinstance, prints a formatted report of the sharding configuration and the information regarding existing chunks in a sharded cluster. The default behavior suppresses the detailed chunk information if the total number of chunks is greater than or equal to 20.The
sh.status()method has the following parameter:ParameterTypeDescriptionverboseboolean
Optional. Determines the level of verbosity.
If
true, the method displays:Full details of the chunk distribution across shards even if you have 20 or more chunks, as well as the number of chunks on each shard.
Details of active mongos instances.
If
false, the method displays:Full details of the chunk distribution across shards only if you have less than 20 chunks. If you have 20 or more chunks, the method instead returns a
too many chunks to print ...message, showing only the number of chunks on each shard.
The default verbose value is
false.See also:
Compatibility
This method is available in deployments hosted in the following environments:
MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
Important
This command is not supported in M0, M2, M5, and Flex clusters. For more information, see Unsupported Commands.
MongoDB Enterprise: The subscription-based, self-managed version of MongoDB
MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB
Output Examples
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> }
The Autosplit displays information on whether autosplit is enabled:
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> 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> } ...
Output Fields
Sharding Version
sh.status.sharding-version._idThe
_idis an identifier for the version details.
sh.status.sharding-version.minCompatibleVersionThe
minCompatibleVersionis the minimum compatible version of the config server.In MongoDB versions earlier than 6.2, this field is included in the
config.versioncollection, but inmongosh2.0.0 and later, the field is not returned in thesh.status()output. Starting in MongoDB 6.2, this field is removed and not returned in anymongoshversion or other client application. Instead, to obtain version information, see the feature compatibility version (fcv).
sh.status.sharding-version.currentVersionThe
currentVersionis the current version of the config server.In MongoDB versions earlier than 6.2, this field is included in the
config.versioncollection, but inmongosh2.0.0 and later, the field is not returned in thesh.status()output. Starting in MongoDB 6.2, this field is removed and not returned in anymongoshversion or other client application. Instead, to obtain version information, see the feature compatibility version (fcv).
sh.status.sharding-version.clusterIdThe
clusterIdis the identification for the sharded cluster.
Active mongos Instances
sh.status.active-mongosesIf
verboseisfalse,sh.status.active-mongoseslists the version and count of the activemongosinstances. Activemongosinstances aremongosinstances that have been pinged within the last 60 seconds.If
verboseistrue,sh.status.active-mongosesreturns a document for each activemongosinstance containing the following fields:FieldData TypeDescription_idString
The hostname and port where the
mongosis running. The_idis formatted as<hostname>:<port>.advisoryHostFQDNsArray of strings
Array of the
mongos's fully qualified domain names (FQDNs).createdDate
When the
mongoswas started.New in version 5.2.
mongoVersionString
Version of MongoDB that the
mongosis running.pingDate
mongosinstances send pings to the config server every 30 seconds. This field indicates the last ping time.upNumberLong
Number of seconds the
mongoshas been up as of the last ping.waitingBoolean
This field is always
trueand is only included for backward compatibility.active mongoses: { "_id" : "<hostname:port>", "advisoryHostFQDNs" : [ "<name>" ], "created" : <ISODate>, "mongoVersion" : <string>, "ping" : <ISODate>, "up" : <long>, "waiting" : <boolean> } ...
Autosplit
sh.status.autosplitsh.status.autosplitindicates whether autosplit is currently enabled.
Note
Starting in MongoDB 6.0.3, automatic chunk splitting is not performed. This is because of balancing policy improvements. Auto-splitting commands still exist, but do not perform an operation.
In MongoDB versions earlier than 6.1:
The
balancerStartcommand and themongoshell helper methodssh.startBalancer()andsh.setBalancerState(true)also enable auto-splitting for the sharded cluster.To disable auto-splitting when the balancer is enabled, you can usesh.disableAutoSplit().The
balancerStopcommand and themongoshell helper methodssh.stopBalancer()andsh.setBalancerState(false)also disable auto-splitting for the sharded cluster.To enable auto-splitting when the balancer is disabled, you can usesh.enableAutoSplit().
The mongo methods
sh.enableBalancing(namespace) and
sh.disableBalancing(namespace) have no affect on the
auto-splitting.
Shards
sh.status.shards._idThe
_iddisplays the name of the shard.
sh.status.shards.hostThe
hostdisplays the host location of the shard.
sh.status.shards.tagsThe
tagsdisplays all the tags for the shard. The field only displays if the shard has tags.
sh.status.shards.stateThe
statedisplays:0if the shard is not shard aware.1if the shard is shard aware.
Balancer
Note
Starting in MongoDB 6.0.3, automatic chunk splitting is not performed. This is because of balancing policy improvements. Auto-splitting commands still exist, but do not perform an operation.
In MongoDB versions earlier than 6.1:
The
balancerStartcommand and themongoshell helper methodssh.startBalancer()andsh.setBalancerState(true)also enable auto-splitting for the sharded cluster.To disable auto-splitting when the balancer is enabled, you can usesh.disableAutoSplit().The
balancerStopcommand and themongoshell helper methodssh.stopBalancer()andsh.setBalancerState(false)also disable auto-splitting for the sharded cluster.To enable auto-splitting when the balancer is disabled, you can usesh.enableAutoSplit().
The mongo methods
sh.enableBalancing(namespace) and
sh.disableBalancing(namespace) have no affect on the
auto-splitting.
sh.status.balancer.currently-enabledcurrently-enabledindicates if the balancer is currently enabled on the sharded cluster.
sh.status.balancer.currently-runningcurrently-runningindicates whether the balancer is currently running, and therefore currently balancing the cluster.
sh.status.balancer.collections-with-active-migrationscollections-with-active-migrationslists 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 thesh.status()output.
sh.status.balancer.failed-balancer-rounds-in-last-5-attemptsfailed-balancer-rounds-in-last-5-attemptsdisplays 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-errorlast-reported-errorlists the most recent balancer error message. If there have been no errors, this field will not appear in thesh.status()output.
sh.status.balancer.time-of-reported-errortime-of-reported-errorprovides the date and time of the most recently-reported error.
sh.status.balancer.migration-results-for-the-last-24-hoursmigration-results-for-the-last-24-hoursdisplays 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-hoursdisplaysNo recent migrations.migration-results-for-the-last-24-hoursincludes all migrations, including those not initiated by the balancer.
Databases
sh.status.databases._idThe
_iddisplays the name of the database.
sh.status.databases.partitionedStarting in MongoDB 6.0 and feature compatibility version (fCV) 6.0, the
partitionedflag only maintains backward compatibility with previous versions. By default, all databases are enabled for sharding regardless of thepartitionedvalue.
sh.status.databases.primaryThe
primarydisplays the primary shard for the database.
sh.status.databases.versionThe
versiondisplays the version information for the database:{ "uuid" : UUID("cc250b66-8638-49f7-a2e8-c6f1220b9d7a"), "lastMod" : 1 } where:
uuidis the database identifier.lastModis the database version.
Sharded Collection
sh.status.databases.<collection>.shard-keyThe
shard-keydisplays the shard key specification document.
sh.status.databases.<collection>.uniqueThe
uniquedisplays whether MongoDB enforces uniqueness on the shard key values (i.e. whether the underlying shard key index is unique).
sh.status.databases.<collection>.balancingDisplays whether the balancer can balance the collection. If the balancer is enabled and this status returns
true, the balancer includes this collection in balancing operations. If the status returnsfalse, it indicates that the balancer does not balance data in this collection.
sh.status.databases.<collection>.chunksThe
chunkslists all the shards and the number of chunks that reside on each shard.
sh.status.databases.<collection>.chunk-detailsThe
chunk-detailslists the details of the chunks [1]:The range of shard key values that define the chunk,
The shard where the chunk resides, and
The last modified timestamp for the chunk.
sh.status.databases.<collection>.tagThe
taglists the details of the tags associated with a range of shard key values.
See also:
| [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). |