sh.addShardTag()

On this page本页内容

Definition定义

sh.addShardTag(shard, tag)

Changed in version 3.4.在版本3.4中更改

This method aliases to sh.addShardToZone() in MongoDB 3.4. 此方法别名为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描述
shardstringThe name of the shard to which to give a specific tag.要为其提供特定标记的分片的名称。
tagstringThe name of the tag to add to the shard.要添加到分片的标记的名称。

Only issue sh.addShardTag() when connected to a mongos instance.仅在连接到mongos实例时发出sh.addShardTag()

Tip提示

Changed in version 4.0.3.在版本4.0.3中更改

By 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:以下示例将三个标记NYCLAXNRT添加到三个分片中:

sh.addShardTag("shard0000", "NYC")
sh.addShardTag("shard0001", "LAX")
sh.addShardTag("shard0002", "NRT")
Tip提示
See also: 参阅:
←  sh.addShard()sh.addShardToZone() →