Database Manual / Reference / Database Commands / Sharding

getShardMap (database command数据库命令)

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.您必须使用管理员数据库来运行getShardMap

Compatibility兼容性

This command is available in deployments hosted in the following environments:此命令在以下环境中托管的部署中可用:

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud:云中MongoDB部署的完全托管服务

Important

This command is not supported in M0 and Flex clusters. For more information, see Unsupported Commands.M0和Flex集群不支持此命令。有关详细信息,请参阅不支持的命令

  • MongoDB Enterprise: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本
  • MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB:MongoDB的源代码可用、免费使用和自我管理版本

Syntax语法

The command has the following syntax:该命令具有以下语法:

db.runCommand("getShardMap")

Output Document输出文档

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.按节点所属的分片或配置服务器分组的节点的连接字符串列表。

Learn More了解更多

For more sharding commands, see Sharding Commands.有关更多分片命令,请参阅分片命令