sh.status()

Definition

  • sh.status()
  • When run on a mongos instance, prints a formatted reportof the sharding configuration and the information regarding existingchunks in a sharded cluster. The default behavior suppressesthe detailed chunk information if the total number of chunks isgreater than or equal to 20.

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

ParameterTypeDescriptionverbosebooleanOptional. Determines the level of verbosity.

If true, the method displays:

  • Full details of the chunk distribution across shards even ifyou have 20 or more chunks, as well as the number of chunkson each shard.
  • Details of active mongos instances.If false, the method displays:

  • Full details of the chunk distribution across shards only ifyou 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.

  • Only the version and number of active mongosinstances.The default verbose value is false.

See also

db.printShardingStatus()

Output Examples

The Sharding Version section displays information on theconfig database:

  1. --- Sharding Status ---
  2. sharding version: {
  3. "_id" : <num>,
  4. "minCompatibleVersion" : <num>,
  5. "currentVersion" : <num>,
  6. "clusterId" : <ObjectId>
  7. }

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

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

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

  1. active mongoses:
  2. <version> : <num>

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

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

The Autosplit displays information on whether autosplitis enabled:

  1. autosplit:
  2. Currently enabled: <yes|no>

The Balancer section lists informationabout the state of the balancer. This provides insight intocurrent balancer operation and can be useful when troubleshooting anunbalanced sharded cluster.

  1. balancer:
  2. Currently enabled: yes
  3. Currently running: yes
  4. Collections with active migrations:
  5. chat.messages started at Mon Nov 05 2018 15:16:45 GMT-0500 (EST)
  6. Failed balancer rounds in last 5 attempts: 0
  7. Migration Results for the last 24 hours:
  8. 1 : Success

The Databases section lists informationon the database(s). For each database, the section displays the name,whether the database has sharding enabled, and the primaryshard for the database.

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

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

  1. <dbname>.<collection>
  2. shard key: { <shard key> : <1 or hashed> }
  3. unique: <boolean>
  4. balancing: <boolean>
  5. chunks:
  6. <shard name1> <number of chunks>
  7. <shard name2> <number of chunks>
  8. ...
  9. { <shard key>: <min range1> } -->> { <shard key> : <max range1> } on : <shard name> <last modified timestamp>
  10. { <shard key>: <min range2> } -->> { <shard key> : <max range2> } on : <shard name> <last modified timestamp>
  11. ...
  12. tag: <tag1> { <shard key> : <min range1> } -->> { <shard key> : <max range1> }
  13. ...

Output Fields

Sharding Version

  • sh.status.sharding-version._id
  • The _id is an identifierfor the version details.
  • sh.status.sharding-version.minCompatibleVersion
  • The minCompatibleVersion isthe minimum compatible version of the config server.
  • sh.status.sharding-version.currentVersion
  • The currentVersion isthe current version of the config server.
  • sh.status.sharding-version.clusterId
  • The clusterId is theidentification for the sharded cluster.

Active mongos Instances

New in version 3.2.

  • sh.status.active-mongoses
  • If verbose is false, sh.status.active-mongoses liststhe version and count of the active mongos instances.Active mongos instances are mongosinstances that have been ping’ed within the last 60 seconds.

If verbose is true, returns for each active mongos instance:

  • Its hostname and port.
  • An array of the instance’s fully qualified domain names (FQDNs).
  • Its MongoDB version.
  • Its most recent ping date and time.
  • Its uptime since the last ping.
  • Its waiting status.
  1. active mongoses:
  2.  
  3. { "_id" : "<hostname:port>", "advisoryHostFQDNs" : [ "<name>" ], "mongoVersion" : <string>, "ping" : <ISODate>, "up" : <long>, "waiting" : <boolean> }
  4. ...

Autosplit

Note

Starting in MongoDB 4.2:

To disable auto-splitting when the balancer is enabled, you canuse sh.disableAutoSplit().

To enable auto-splitting when the balancer is disabled, you canuse sh.enableAutoSplit().

The mongo methodssh.enableBalancing(namespace) andsh.disableBalancing(namespace) have no affect on theauto-splitting.

Shards

  • sh.status.shards._id
  • The _id displays the name of the shard.
  • sh.status.shards.host
  • The host displays the host locationof the shard.
  • sh.status.shards.tags
  • The tags displays all the tags forthe shard. The field only displays if the shard has tags.
  • sh.status.shards.state

New in version 3.4.

The state displays:

  • 0 if the shard is not shard aware.
  • 1 if the shard is shard aware.

Balancer

New in version 3.0.0: sh.status() added the balancer field.

Note

Starting in MongoDB 4.2:

To disable auto-splitting when the balancer is enabled, you canuse sh.disableAutoSplit().

To enable auto-splitting when the balancer is disabled, you canuse sh.enableAutoSplit().

The mongo methodssh.enableBalancing(namespace) andsh.disableBalancing(namespace) have no affect on theauto-splitting.

  • sh.status.balancer.currently-running
  • currently-running indicates whetherthe balancer is currently running, and therefore currentlybalancing the cluster.
  • sh.status.balancer.collections-with-active-migrations
  • collections-with-active-migrationslists the names of any collections with active migrations, andspecifies when the migration began. If there are no activemigrations, 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-attemptsdisplays the number of balancer rounds that failed, from amongthe last five attempted rounds. A balancer round will fail when a chunkmigration fails.
  • sh.status.balancer.last-reported-error
  • last-reported-error lists the mostrecent balancer error message. If there have been no errors, thisfield will not appear in the sh.status() output.
  • sh.status.balancer.time-of-reported-error
  • time-of-reported-error providesthe date and time of the most recently-reported error.

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

Databases

  • sh.status.databases._id
  • The _id displays the name of the database.
  • sh.status.databases.partitioned
  • The partitioned displays whetherthe database has sharding enabled. If true, the database hassharding enabled.
  • sh.status.databases.version

New in version 4.0: Only available for featureCompatibilityVersion4.0 or greater.

The version displays theversion information for the database:

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

where:

  • uuid is the database identifier.
  • lastMod is the database version.

Sharded Collection

  • sh.status.databases.<collection>.shard-key
  • The shard-key displays the shardkey specification document.
  • sh.status.databases.<collection>.unique
  • The unique displayswhether MongoDB enforces uniqueness on the shard key values (i.e.whether the underlying shard key index is unique).

New in version 3.2.

  • sh.status.databases.balancing
  • The balancing displayswhether balancing is enabled (true) or disabled (false) forthe collection.

New in version 3.2.

  • sh.status.databases.<collection>.chunks
  • The chunks lists all the shardsand the number of chunks that reside on each shard.
  • sh.status.databases.<collection>.chunk-details
  • The chunk-details lists the detailsof 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>.tag
  • The tag lists the details ofthe tags associated with a range of shard key values.
[1](1, 2) The sharded collection section, by default,displays the chunk information if the total number of chunks is lessthan 20. To display the information when you have 20 or more chunks,call the sh.status() methods with the verbose parameterset to true, i.e. sh.status(true).