- Reference >
mongoShell Methods >- Sharding Methods >
- sh.addShardToZone()
sh.addShardToZone()¶
On this page
Definition¶
-
sh.addShardToZone(shard, zone)¶ New in version 3.4: Associates a shard with a zone. MongoDB associates this shard with the given zone. Chunks that are covered by the zone are assigned to shards associated with the zone.
Parameter Type Description shardstring The name of the shard to which to associate the zone.zonestring The name of the zone to associate with the shardOnly issue
sh.addShardToZone()when connected to amongosinstance.
Behavior¶
You can associate a zone with multiple shards, and a shard can associate with multiple zones.
See the zone manual page for more information on zones in sharded clusters.
Ranges¶
MongoDB effectively ignores zones that do not have at least one range of shard key values associated with it.
To associate a range of shard key values with a zone, use the
sh.updateZoneKeyRange() method.
Security¶
For sharded clusters running with authentication, you
must authenticate as a user whose privileges include update on
the config.shards collection or the config database.
The clusterAdmin or clusterManager built-in roles have
the appropriate permissions for issuing sh.addShardToZone(). See the
Role-Based Access Control manual page for more
information.
Example¶
The following example adds three zones, NYC, LAX, and NRT,
associating each to a shard:
A shard can associate with multiple zones. The following example associates
LGA to shard0000:
shard0000 associates with both the LGA zone and the JFK zone. In a
balanced cluster, MongoDB routes reads and writes covered by either zone to
shard0000.
See also