The MongoDB balancer distributes sharded data across shards so each shard carries a more uniform share of a collection’s data, while respecting configured zones. section 9.3.8
Operational behavior and guidance:
- The config server replica set’s primary manages balancing, which usually remains transparent to applications but can cause slight performance effects. section 9.3.8
- A shard participates in only one migration at a time; a cluster with n shards can run up to n/2 migrations concurrently. section 9.3.8
- Balancing rounds begin when the data-size difference between the most- and least-loaded shards exceeds the configured threshold. section 9.3.8
- Schedule a balancing window to reduce disruption during peak production traffic, and verify that the balancer is running before relying on it. section 9.3.8
- Prefer automatic range transfers; use manual presplitting or migration for empty collections, high-volume ingestion, or workloads the balancer cannot distribute within its window. section 9.3.9
use config
Connect to mongos, switch to the config database, and configure the balancer window with the related start, stop, and status commands. section 9.3.8
Presplitting route data
For an empty sample_training.routes collection, split around meaningful source-airport, destination-airport, and airline combinations such as JFK–LHR with British Airways, then distribute the resulting ranges when necessary. section 9.3.9
// Split points to segment the collection into chunks ➥ // based on common routes and airlines var splitPoints = [ { "src_airport": "JFK", "dst_airport": "LHR", ➥"airline.name": "British Airways" }, { "src_airport": "LAX", "dst_airport": "NRT", ➥"airline.name": "Japan Airlines" }, { "src_airport": "DXB", "dst_airport": "SYD", ➥"airline.name": "Emirates" } ]; // Loop through the split points and apply the 'split' command splitPoints.forEach(function(point) { db.adminCommand({ split: "sample_training.routes", middle: point }); });
Apply route-based split points with the split command before considering manual range placement. section 9.3.9
