Docs Menu

Docs HomeDevelop ApplicationsMongoDB Manual

sh.addShardTag()

On this page

  • Definition
  • Example
sh.addShardTag(shard, tag)

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.

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 a mongos instance.

Tip

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, NYC, LAX, and NRT, to three shards:

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

Tip

See also:

←  sh.addShard()sh.addShardToZone() →

On this page