getShardMapgetShardMap返回有关集群的以下信息:分片和配置服务器副本集的名称
组成集群分片和配置服务器副本集的节点的主机名和连接字符串
您必须使用管理员数据库才能运行
getShardMap。
兼容性
此命令可用于以下环境中托管的部署:
MongoDB Atlas:用于云中 MongoDB 部署的完全托管服务
重要
M0 和 Flex 集群不支持此命令。有关更多信息,请参阅不支持的命令。
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
语法
该命令具有以下语法:
db.runCommand("getShardMap")
输出文档
该命令返回的输出示例如下:
{ map: { shard01: 'shard01/localhost:27018,localhost:27019,localhost:27020', shard02: 'shard02/localhost:27021,localhost:27022,localhost:27023', shard03: 'shard03/localhost:27024,localhost:27025,localhost:27026', config: 'configRepl/localhost:27027' }, hosts: { 'localhost:27026': 'shard03', 'localhost:27020': 'shard01', 'localhost:27021': 'shard02', 'localhost:27024': 'shard03', 'localhost:27022': 'shard02', 'localhost:27018': 'shard01', 'localhost:27025': 'shard03', 'localhost:27019': 'shard01', 'localhost:27023': 'shard02', 'localhost:27027': 'config' }, connStrings: { 'shard01/localhost:27018,localhost:27019,localhost:27020': 'shard01', 'shard02/localhost:27021,localhost:27022,localhost:27023': 'shard02', 'shard03/localhost:27024,localhost:27025,localhost:27026': 'shard03', 'configRepl/localhost:27027': 'config' }, ok: 1, '$clusterTime': { clusterTime: Timestamp({ t: 1760637565, i: 2 }), signature: { hash: Binary.createFromBase64('AAAAAAAAAAAAAAAAAAAAAAAAAAA=', 0), keyId: Long('0') } }, operationTime: Timestamp({ t: 1760637565, i: 2 }) }
该命令返回以下字段:
字段 | 说明 |
|---|---|
| 集群中的分片列表、集群的配置服务器以及集群中每个节点的主机名和端口。 |
| 集群节点的主机名和端口列表以及它们映射到的分片或配置服务器。 |
| 按节点所属的分片或配置服务器分组的节点的连接字符串列表。 |
了解详情
更多分片命令,请参阅分片命令。