How do I list of all servers ( mongos,config,shards) for sharded cluster. from mongos shell?

How I list the entire cluster information from mongos - mongo shell? Like I am looking a single command to list similar to below information:
mongos:
mongos1:27017
mongos2:27017
config:
mongoc1:27018
mongoc2:27018
mongoc3:27018
shards:
sh1:
mongod1:27019
mongod2:27019
mongod3:27019
sh2:
mongod4:27019
mongod5:27019
mongod6:27019

Hi @Rama_Mekala1 - Welcome to the community.

The closest single command I could think of that would produce a similar output would be db.runCommand("getShardMap") which results in the following output based off my test environment:

[direct: mongos] admin> db.runCommand("getShardMap")
{
  map: {
    config: 'configRepl/localhost:27024',
    shard01: 'shard01/localhost:27018,localhost:27019,localhost:27020',
    shard02: 'shard02/localhost:27021,localhost:27022,localhost:27023'
  },
  ...
}

It does not include the mongos hostname or port info though from what I have seen from the output (from my test environment).

Perhaps you could write a script that runs multiple commands to gather the required information (e.g. sh.status() for mongos details combined with the above db.runCommand("getShardMap") ) . Additionally, there are some examples using multiple --eval options in the mongosh document here.

Hope this helps.

Regards,
Jason

3 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.