On this page本页内容
You can only run 您只能从addShardToZone on the admin database from a mongos instance.mongos实例在admin数据库上运行addShardToZone。
The addShardToZone command has the following syntax:addShardToZone命令具有以下语法:
db.adminCommand(
{
addShardToZone: <string>,
zone: <string>
}
)
The command takes the following fields:该命令接受以下字段:
| addShardtoZone | string |
|
| zone | string |
|
mongosh provides the helper method 提供了助手方法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 a sharded cluster.有关分片化集群中的区域的更多信息,请参阅区域手册页面。
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 要将分片键值范围与区域相关联,请使用updateZoneKeyRange database command, or the sh.updateZoneKeyRange() shell helper.updateZoneKeyRange数据库命令或sh.updateZoneKeyRange()shell助手。
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 (available 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 addShardToZone. clusterAdmin或clusterManager内置角色具有发出addShardToZone的适当权限。See the documentation page for Role-Based Access Control for more information.有关详细信息,请参阅基于角色的访问控制的文档页。
The following example associates 以下示例将shard0000 with zone JFK:shard0000与区域JFK相关联:
db.adminCommand( { addShardToZone : "shard0000" , zone : "JFK" } )
A shard can associate with multiple zones. 分片可以与多个区域关联。The following example associates 以下示例将LGA to shard0000:LGA与shard0000关联:
db.adminCommand( { addShardToZone : "shard0000" , zone : "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。