Viewing shard-cluster participants

Run the db.runCommand MongoDB shell command with listShards syntax to list the Enterprise Replication group names, hosts, and port numbers of all shard servers in a shard cluster.

Procedure

  1. Run the mongo command.
    The command starts the MongoDB shell.
  2. Run the listShards command:
    db.runCommand({listShards:1})

Results

The listShards command produces output in the following structure:
{
        "serverUsed" : "server_host/IP_address",
        "shards" : [
                {
                        "_id" : "ER_group_name_1",
                        "host" : "host_1:port_1"
                },
                {
                        "_id" : "ER_group_name_2",
                        "host" : "host_2:port_2"
                },
                {
                        "_id" : "ER_group_name_x",
                        "host" : "host_x:port_x"
                }
        ],
        "ok" : 1
}
ER_group_name
The Enterprise Replication group name of a shard server.
host
The host for a shard-cluster participant. The host can be a localhost name or a full domain name.
IP_address
The IP address of the database server that the listener is connected to.
port
The port number that a shard-cluster participant uses to communicate with other shard-cluster participants.
server_host
The host for the database server that the listener is connected to. The host can be a localhost name or a full domain name.

Example

For this example, you have a shard cluster defined by the following command:
prompt> db.runCommand({"addShard":["myhost1.ibm.com:9201",
   "myhost2.ibm.com:9202","myhost3.ibm.com:9203",
   "myhost4.ibm.com:9204","myhost5.ibm.com:9205"]})

The following example output is shown when the listShards command is run in the MongoDB shell, and the listener is connected to the database server at myhost1.ibm.com.

Figure 1: listShards command output for a shard cluster
{
        "serverUsed" : "myhost1.ibm.com/192.0.2.0:9200",
        "shards" : [
                {
                        "_id" : "g_myserver1",
                        "host" : "myhost1.ibm.com:9200"
                },
                {
                        "_id" : "g_myserver2",
                        "host" : "myhost2.ibm.com:9202"
                },
                {
                        "_id" : "g_myserver3",
                        "host" : "myhost3.ibm.com:9203"
                }
                {
                        "_id" : "g_myserver4",
                        "host" : "myhost4.ibm.com:9204"
                }
                {
                        "_id" : "g_myserver5",
                        "host" : "myhost5.ibm.com:9205"
                }
        ],
        "ok" : 1
}