Definition
removeShardFromZoneThe
removeShardFromZoneadministrative command removes the association between a shard and a zone.Tip
In
mongosh, this command can also be run through thesh.removeShardFromZone()helper method.Helper methods are convenient for
mongoshusers, but they may not return the same level of information as database commands. In cases where the convenience is not needed or the additional return fields are required, use the database command.
Compatibility
This command is available in deployments hosted in the following environments:
MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
MongoDB Enterprise: The subscription-based, self-managed version of MongoDB
MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB
Syntax
You can only run removeShardFromZone on the admin database
from a mongos instance.
The command has the following syntax:
db.adminCommand( { removeShardFromZone: <string>, zone: <string> } )
Command Fields
The command takes the following fields:
Field | Type | Description |
|---|---|---|
string | The name of the shard from which to remove the zone association. | |
string | The name of the zone whose association with the shard you want to remove. |
mongosh provides the helper method
sh.removeShardFromZone().
Behavior
removeShardFromZone does not remove ranges associated with the
zone.
To completely remove a zone from the cluster, you must run
removeShardFromZone on each shard associated with the zone.
If the shard specified is the last shard associated with the zone, you must
ensure there are no remaining shard key ranges associated with the zone. Use
updateZoneKeyRange to remove any existing ranges associated with
the zone before running removeShardFromZone.
See the zone manual page for more information on zones in sharded clusters.
Security
For sharded clusters that enforce access control, you must authenticate either as:
a user whose privileges include:
updateon theshardscollection in theconfigdatabase, andfindon thetagscollection in theconfigdatabase;
or, alternatively
a user whose privileges include
enableShardingon the cluster resource.
The clusterAdmin or clusterManager built-in roles have
the appropriate permissions for issuing removeShardFromZone. See
the Role-Based Access Control manual page for more
information.
Example
The following example removes the association between shard0000 and zone
NYC:
db.adminCommand( { removeShardFromZone : "shard0000" , zone : "NYC" } )