Docs Menu
Docs Home
/
MongoDB Manual
/ / /

Update an Existing Shard Zone

On this page

  • About this Task
  • Before you Begin
  • Add a shard to a zone called NYC
  • Specify a range of zipcode values for the NYC zone
  • Steps
  • Stop the balancer
  • Remove the current NYC range from the zone
  • Update the zone key range for the NYC zone
  • Restart the balancer
  • Learn More

After you specify a range of values for a shard zone, you can update the shard zone range if your application's requirements change.

To update an existing shard zone, perform these steps:

  1. Stop the balancer.

  2. Remove the old range from the zone.

  3. Update the zone's range.

  4. Restart the balancer.

  • Zone ranges are inclusive of the lower boundary and exclusive of the upper boundary.

  • After you modify a zone, the balancer must migrate chunks to the appropriate zones based on the new range of values. Until balancing completes, some chunks may reside on the wrong shard given the configured zones for the sharded cluster.

To complete this tutorial, you must deploy a sharded cluster with a sharded collection and create a zone to modify.

This example uses a sharded collection named users in the records database, sharded by the zipcode field.

1
sh.addShardToZone(<shard name>, "NYC")
2
sh.updateZoneKeyRange("records.users", { zipcode: "10001" }, { zipcode: "10281" }, "NYC" )

The following procedure modifies the range of zipcode values for the NYC zone to be 11201 through 11240.

1
sh.stopBalancer()
2
sh.removeRangeFromZone("records.user", { zipcode: "10001" }, { zipcode: "10281" } )
3
sh.updateZoneKeyRange("records.users", { zipcode: "11201" }, { zipcode: "11240" }, "NYC" )
4
sh.startBalancer()
← Manage Shard Zones