shardingState

shardingState has the following prototype form:

  1. { shardingState: 1 }

To run the command, you must run against the admin database. Seedb.adminCommand().

Behavior

For shardingState to detect that a mongod is amember of a sharded cluster, the mongod must satisfy thefollowing conditions:

  • the mongod is a primary member of a replica set, and
  • the mongod instance is a member of a shardedcluster.If shardingState detects that a mongod is amember of a sharded cluster, shardingState returns adocument that resembles the following prototype:
  1. {
  2. "enabled" : true,
  3. "configServer" : "<configdb-string>",
  4. "shardName" : "<string>",
  5. "shardHost" : "string:",
  6. "versions" : {
  7. "<database>.<collection>" : Timestamp(<...>),
  8. "<database>.<collection>" : Timestamp(<...>)
  9. },
  10. "ok" : 1,
  11. "$clusterTime" : {
  12. "clusterTime" : Timestamp(1510716515, 1),
  13. "signature" : {
  14. "hash" : BinData(0,"B2ViX7XLzFLS5Fl9XEuFXbwKIM4="),
  15. "keyId" : NumberLong("6488045157173166092")
  16. }
  17. },
  18. "operationTime" : Timestamp(1510716515, 1)
  19. }

Otherwise, shardingState will return the following document:

  1. {
  2. "enabled" : false,
  3. "ok" : 1,
  4. "$clusterTime" : {
  5. "clusterTime" : Timestamp(1510716515, 1),
  6. "signature" : {
  7. "hash" : BinData(0,"B2ViX7XLzFLS5Fl9XEuFXbwKIM4="),
  8. "keyId" : NumberLong("6488045157173166092")
  9. }
  10. },
  11. "operationTime" : Timestamp(1510716515, 1)
  12. }

The response from shardingState when used with aconfig server is:

  1. {
  2. "enabled" : false,
  3. "ok" : 1,
  4. "operationTime" : Timestamp(1510767613, 1),
  5. "$gleStats" : {
  6. "lastOpTime" : Timestamp(0, 0),
  7. "electionId" : ObjectId("7fffffff0000000000000001")
  8. },
  9. "$clusterTime" : {
  10. "clusterTime" : Timestamp(1510767613, 1),
  11. "signature" : {
  12. "hash" : BinData(0,"IwBZ4SZjIMI5NdM62NObV/R31GM="),
  13. "keyId" : NumberLong("6488693018630029321")
  14. }
  15. }
  16. }

Note

mongos instances do not provide theshardingState.

Warning

This command obtains a write lock on the affected database andwill block other operations until it has completed; however, theoperation is typically short lived.