Docs Menu

Docs HomeMongoDB Manual

getShardMap

On this page

  • Compatibility
  • Syntax
  • Learn More
getShardMap

getShardMap returns the following information about your cluster:

  • The names of your shards and the config server replica set

  • Hostnames and connection strings for the nodes that comprise the cluster's shards and the config server replica set

You must use the admin database to run getShardMap.

This command is available in deployments hosted in the following environments:

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud

Note

This command is not supported in M0, M2, and M5 clusters or in serverless instances. For more information, see Unsupported Commands.

The command has the following syntax:

db.runCommand("getShardMap")

Here's an example of the output the command returns:

{
map: {
shard01: 'shard01/localhost:27018,localhost:27019,localhost:27020,localhost:27021,localhost:27022',
shard02: 'shard02/localhost:27023,localhost:27024,localhost:27025,localhost:27026,localhost:27027',
shard03: 'shard03/localhost:27028,localhost:27029,localhost:27030,localhost:27031,localhost:27032',
config: 'configRepl/localhost:27033',localhost:27034,localhost:27035,localhost:27036,localhost:27037'
},
hosts: {
'localhost:27021': 'shard01',
'localhost:27022': 'shard01',
'localhost:27028': 'shard03',
'localhost:27026': 'shard02',
'localhost:27020': 'shard01',
'localhost:27032': 'shard03',
'localhost:27027': 'shard02',
'localhost:27024': 'shard02',
'localhost:27018': 'shard01',
'localhost:27019': 'shard01',
'localhost:27031': 'shard03',
'localhost:27025': 'shard02',
'localhost:27029': 'shard03',
'localhost:27023': 'shard02',
'localhost:27030': 'shard03',
'localhost:27033': 'config'
'localhost:27036': 'config'
'localhost:27034': 'config'
'localhost:27037': 'config'
'localhost:27035': 'config'
},
connStrings: {
'shard01/localhost:27018,localhost:27019,localhost:27020,localhost:27021,localhost:27022': 'shard01',
'shard01/localhost:27019,localhost:27020,localhost:27021': 'shard01',
'shard01/localhost:27020,localhost:27021': 'shard01',
'shard01/localhost:27021': 'shard01',
'shard02/localhost:27023,localhost:27024,localhost:27025,localhost:27026,localhost:27027': 'shard02',
'shard02/localhost:27025,localhost:27026,localhost:27027': 'shard02',
'shard02/localhost:27025,localhost:27027': 'shard02',
'shard03/localhost:27028,localhost:27029,localhost:27030,localhost:27031,localhost:27032': 'shard03',
'shard03/localhost:27032': 'shard03',
'configRepl/localhost:27033',localhost:27036,localhost:27034,localhost:27037,localhost:27035': 'config'
},
ok: 1
}

The command returns the following fields:

Field
Description
"map"
List of shards in the cluster, the config server for the cluster, and the hostname and port for every node in the cluster.
"hosts"
List of hostnames and ports for the nodes of the cluster and the shards or config server to which they map.
"connStrings"
List of connection strings for the nodes grouped by the shard or config server the node belongs to.

For more sharding commands, see Sharding Commands.

←  flushRouterConfiggetShardVersion →