sh.addShardTag()

Definition

  • sh.addShardTag(shard, tag)

Changed in version 3.4: This method aliases to sh.addShardToZone() in MongoDB 3.4. The functionality specifiedbelow 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 theseidentifiers to direct chunks that fall within atagged range to specific shards. sh.addTagRange()associates chunk ranges with tag ranges.

ParameterTypeDescriptionshardstringThe 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 amongos instance.

Tip

Changed in version 4.0.3: By defining the zones and the zone ranges before sharding an emptyor a non-existing collection, the shard collection operation createschunks for the defined zone ranges as well as any additional chunksto cover the entire range of the shard key values and performs aninitial chunk distribution based on the zone ranges. This initialcreation and distribution of chunks allows for faster setup of zonedsharding. After the initial distribution, the balancer manages thechunk 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, tothree shards:

  1. sh.addShardTag("shard0000", "NYC")
  2. sh.addShardTag("shard0001", "LAX")
  3. sh.addShardTag("shard0002", "NRT")

See also

sh.addTagRange() and sh.removeShardTag().