- Reference >
- JavaScript Methods >
- sh.addTagRange()
sh.addTagRange()¶
-
sh.addTagRange(namespace, minimum, maximum, tag)¶ New in version 2.2.
Parameters: - namespace (string) – Specifies the namespace, in the form of
<database>.<collection>of the sharded collection that you would like to tag. - minimum (document) – Specifies 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) – Specifies 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) – Specifies the name of the tag to attach the range
specified by the
minimumandmaximumarguments to.
sh.addTagRange()attaches a range of values of the shard key to a shard tag created using thesh.addShardTag()method. Use this operation to ensure that the documents that exist within the specified range exist on shards that have a matching tag.Always issue
sh.addTagRange()when connected to amongosinstance.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 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}, create a tag range covering ZIP codes in New York State:See also
- namespace (string) – Specifies the namespace, in the form of