- Reference >
mongo
Shell Methods >- Sharding Methods >
- sh.addTagRange()
sh.addTagRange()¶
On this page
Definition¶
-
sh.
addTagRange
(namespace, minimum, maximum, tag)¶ New in version 2.2.
Attaches a range of shard key values to a shard tag created using the
sh.addShardTag()
method.sh.addTagRange()
takes the following arguments:Parameter Type Description namespace
string The namespace of the sharded collection to tag. minimum
document The minimum value of the shard key range to include in the tag. Specify the minimum value in the form of <fieldname>:<value>
. This value must be of the same BSON type or types as the shard key.maximum
document The maximum value of the shard key range to include in the tag. Specify the maximum value in the form of <fieldname>:<value>
. This value must be of the same BSON type or types as the shard key.tag
string The name of the tag to attach the range specified by the minimum
andmaximum
arguments to.Use
sh.addShardTag()
to ensure that the balancer migrates documents that exist within the specified range to a specific shard or set of shards.Only issue
sh.addTagRange()
when connected to amongos
instance.Note
If you add a tag range to a collection using
sh.addTagRange()
and then later drop the collection or its database, MongoDB does not remove the tag association. If you later create a new collection with the same name, the old tag association will apply to the new collection.
Example¶
Given a shard key of {state: 1, zip: 1}
, the following operation
creates a tag range covering zip codes in New York State: