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
- Run the mongo command.The command starts the MongoDB shell.
-
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.