sh.addShardTag()
On this page本页内容
Definition定义
sh.addShardTag(shard, tag)
Changed in version 3.4.3.4版更改。This method aliases to此方法在MongoDB 3.4中别名为sh.addShardToZone()
in MongoDB 3.4.sh.addShardToZone()
。The functionality specified below still applies to MongoDB 3.2.下面指定的功能仍然适用于MongoDB 3.2。MongoDB 3.4 provides Zone sharding as the successor to tag-aware sharding.MongoDB 3.4提供了区域分片作为标记感知分片的继承。Associates a shard with a tag or identifier. MongoDB uses these identifiers to direct chunks that fall within a tagged range to specific shards.将分片与标记或标识符相关联。MongoDB使用这些标识符将属于标记范围内的区块定向到特定的分片。sh.addTagRange()
associates chunk ranges with tag ranges.将区块范围与标记范围相关联。Parameter参数Type类型Description描述shard
string The name of the shard to which to give a specific tag.要为其提供特定标记的分片的名称。tag
string The name of the tag to add to the shard.要添加到分片的标记的名称。Only issue仅在连接到sh.addShardTag()
when connected to amongos
instance.mongos
实例时发出sh.addShardTag()
。TipBy defining the zones and the zone ranges before sharding an empty or a non-existing collection, the shard collection operation creates chunks for the defined zone ranges as well as any additional chunks to cover the entire range of the shard key values and performs an initial chunk distribution based on the zone ranges.通过在对空集合或不存在的集合进行分片之前定义区域和区域范围,分片集合操作为定义的区域范围以及任何额外的块创建块,以覆盖分片键值的整个范围,并基于区域范围执行初始块分布。This initial creation and distribution of chunks allows for faster setup of zoned sharding.这种块的初始创建和分布允许更快地设置分区分片。After the initial distribution, the balancer manages the chunk distribution going forward.在初始分发之后,平衡器管理接下来的块分发。See Pre-Define Zones and Zone Ranges for an Empty or Non-Existing Collection for an example.有关示例,请参阅空集合或不存在集合的预定义分区和分区范围。
Example实例
The following example adds three tags, 以下示例将NYC
, LAX
, and NRT
, to three shards:NYC
、LAX
和NRT
三个标记添加到三个分片中:
sh.addShardTag("shard0000", "NYC")
sh.addShardTag("shard0001", "LAX")
sh.addShardTag("shard0002", "NRT")