sh.listShards()
On this page
Definition
sh.listShards()
returns a list of the
configured shards in a sharded cluster. This
information matches the shards
field
returned by the listShards
database command.
Syntax
sh.listShards()
has the following syntax:
sh.listShards()
Behavior
The output for sh.listShards()
returns an array of documents,
each describing one shard. Each document may contain the
following fields:
Field | Description |
---|---|
| Name of the shard. |
| Hostname of the shard. If the shard is a replica set,
|
| If |
| List of zones to which the shard belongs. |
| Internal field used during the addShard sequence to ensure that all steps and configuration necessary to add the shard to the cluster are completed. |
Example
The following code runs
sh.listShards()
and provides
an example output array:
sh.listShards()
[ { "_id": "shard01", "host": "shard01/host1:27018,host2:27018,host3:27018", "state": 1 }, { "_id": "shard02", "host": "shard02/host4:27018,host5:27018,host6:27018", "tags": [ "NYC" ], "state": 1 }, { "_id": "shard03", "host": "shard03/host7:27018,host8:27018,host9:27018", "state": 1 } ]