listShards

Definition

  • listShards
  • The listShards command returns a list of the configuredshards in a sharded cluster. listShards is onlyavailable on mongos instances and must be issued againstthe admin database.

The command takes the following form:

  1. { listShards: 1 }

Example

The following operation runs listShards against themongos admin database:

  1. db.adminCommand({ listShards: 1 })

The following document is an example of the output from alistShards command:

  1. {
  2. "shards": [
  3. {
  4. "_id": "shard01",
  5. "host": "shard01/host1:27018,host2:27018,host3:27018",
  6. "state": 1
  7. },
  8. {
  9. "_id": "shard02",
  10. "host": "shard02/host4:27018,host5:27018,host6:27018",
  11. "tags": [ "NYC" ],
  12. "state": 1
  13. },
  14. {
  15. "_id": "shard03",
  16. "host": "shard03/host7:27018,host8:27018,host9:27018",
  17. "maxSize": NumberLong("1024"),
  18. "state": 1
  19. }
  20. ],
  21. "ok": 1,
  22. "$clusterTime" : {
  23. "clusterTime" : Timestamp(1510716515, 1),
  24. "signature" : {
  25. "hash" : BinData(0,"B2ViX7XLzFLS5Fl9XEuFXbwKIM4="),
  26. "keyId" : NumberLong("6488045157173166092")
  27. }
  28. },
  29. "operationTime" : Timestamp(1510716515, 1)
  30. }

Output

listShards returns a document that includes:

  • A shards field which contains an array of documents, eachdescribing one shard. Each document may contain the following fields:

FieldDescription_idThe name of the shard.hostThe hostname of the shard. If the shard is a replica set,host lists the hostname of each mongod instance in thereplica set.drainingIf true, indicates that removeShardhas been called for this shard and it is in the process ofbeing drained.tagsA list of zones to which the shard belongs.maxSizeThe configuredmaximum storage size of the shard in megabytes. This includesall data files on the shard including the local andadmin databases. If exceeded, this shard will not receiveany more chunks.stateAn internal field used during theaddShard sequence to ensure that allsteps and configuration necessary to add the shard to thecluster are completed.

  • The ok status field, the operationTime field, and the$clusterTime field for the operation. For details on thesefields, see Response.