On this page本页内容
sh.addShardToZone(shard, zone)
Associates a shard with a zone. 将分片与分区相关联。MongoDB associates this shard with the given zone. MongoDB将此分片与给定区域相关联。Chunks that are covered by the zone are assigned to shards associated with the zone.分区覆盖的区块被指定给与分区关联的分片。
shard | string |
|
zone | string |
|
Only issue 仅在连接到sh.addShardToZone()
when connected to a mongos
instance.mongos
实例时发出sh.addShardToZone()
。
You can associate a zone with multiple shards, and a shard can associate with multiple zones.您可以将一个分区与多个分片相关联,一个分片可以与多个分区相关联。
See the zone manual page for more information on zones in sharded clusters.有关分片集群中分区的详细信息,请参阅分区手册页面。
MongoDB effectively ignores zones that do not have at least one range of shard key values associated with it.MongoDB实际上忽略了没有至少一个范围的分片键值与其关联的区域。
To associate a range of shard key values with a zone, use the 要将一系列分片键值与区域关联,请使用sh.updateZoneKeyRange()
method.sh.updateZoneKeyRange()
方法。
Starting in MongoDB 4.0.2, you can run 从MongoDB 4.0.2开始,您可以对未存储的集合或不存在的集合运行updateZoneKeyRange
database command and its helpers sh.updateZoneKeyRange()
and sh.addTagRange()
on an unsharded collection or a non-existing collection.updateZoneKeyRange
数据库命令及其助手sh.updateZoneKeyRange()
和sh.addTagRange()
。
Changed in version 4.0.3.在版本4.0.3中更改。
For sharded clusters that enforce access control, you must authenticate as a user whose privileges include either:对于强制访问控制的分片群集,您必须作为具有以下权限之一的用户进行身份验证:
update
on the shards
collection in the config
database; or, alternatively,config
数据库中的shards
集合;或者,作为替代方案,enableSharding
on the cluster resource (Starting in version 4.2.2, 4.0.14, 3.6.16).enableSharding
(从版本4.2.2、4.0.14、3.6.16开始)。The clusterAdmin
or clusterManager
built-in roles have the appropriate permissions for issuing sh.addShardToZone()
. clusterAdmin
或clusterManager
内置角色具有发出sh.addShardToZone()
的相应权限。See the Role-Based Access Control manual page for more information.有关详细信息,请参阅基于角色的访问控制手册页。
The following example adds three zones, 以下示例添加了三个分区:NYC
, LAX
, and NRT
, associating each to a shard:NYC
、LAX
和NRT
,将每个分区与一个分片相关联:
sh.addShardToZone("shard0000", "JFK") sh.addShardToZone("shard0001", "LAX") sh.addShardToZone("shard0002", "NRT")
A shard can associate with multiple zones. 分片可以与多个区域关联。The following example associates 以下示例将LGA
to shard0000
:LGA
与shard0000
关联:
sh.addShardToZone("shard0000", "LGA")
shard0000
associates with both the LGA
zone and the JFK
zone. shard0000
与LGA
区域和JFK
区域都关联。In a balanced cluster, MongoDB routes reads and writes covered by either zone to 在平衡集群中,MongoDB将任一区域覆盖的读写路由到shard0000
.shard0000
。