Balancer state, active window and per-collection balancing
MongoDBShardingCommand
// Is the balancer enabled, is it running a round right now:
sh.getBalancerState()
db.adminCommand({ balancerStatus: 1 })
// Run the balancer only between 01:00 and 05:00 (on mongos):
db.getSiblingDB("config").settings.updateOne({ _id: "balancer" }, { $set: { activeWindow: { start: "01:00", stop: "05:00" } } }, { upsert: true })
// Remove the window:
db.getSiblingDB("config").settings.updateOne({ _id: "balancer" }, { $unset: { activeWindow: true } })
// Disable / enable balancing for a single collection:
sh.disableBalancing("shop.musteri")
sh.enableBalancing("shop.musteri")
// Whether the collection is balanced (4.4+):
db.adminCommand({ balancerCollectionStatus: "shop.musteri" })What it does
Shows whether the balancer is enabled and running a round, restricts chunk migrations to a time window and disables or enables balancing for a single collection.
When to use it
When chunk migrations hurt daytime performance, during the backup window or while isolating a migration problem on one collection.
Caution
A window that is too narrow cannot keep up with data growth and shards become unbalanced; check balance regularly with balancerCollectionStatus. A migration started before the window closes runs until it finishes. If per-collection balancing is left disabled, that collection keeps growing on a single shard.