Changed in version 3.4: This method aliases to
sh.addShardToZone()in MongoDB 3.4. The functionality specified below still applies to MongoDB 3.2. MongoDB 3.4 provides Zone sharding as the successor to tag-aware sharding.
Associates a shard with a tag or identifier. MongoDB uses these identifiers to direct chunks that fall within a tagged range to specific shards.
sh.addTagRange()associates chunk ranges with tag ranges.ParameterTypeDescription
shardstringThe name of the shard to which to give a specific tag.
tagstringThe name of the tag to add to the shard.
Changed in version 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.
The following example adds three tags,
sh.addShardTag("shard0000", "NYC") sh.addShardTag("shard0001", "LAX") sh.addShardTag("shard0002", "NRT")