sh.setBalancerState()

On this page本页内容

Description描述

sh.setBalancerState(state)

Enables or disables the balancer. 启用或禁用平衡器Starting in MongoDB 4.2, the method also enables auto-splitting if enabling the balancer and disables auto-splitting if disabling the balancer.从MongoDB 4.2开始,如果启用平衡器,该方法还启用自动拆分,如果禁用平衡器,则禁用自动拆分。

Use sh.getBalancerState() to determine if the balancer is currently enabled or disabled and sh.isBalancerRunning() to check its current state.使用sh.getBalancerState()确定平衡器当前是否已启用或禁用,使用sh.isBalancerRunning()检查其当前状态。

Important重要

You can only run sh.setBalancerState() on a mongos instance. 只能在mongos实例上运行sh.setBalancerState()sh.setBalancerState() errors if run on mongod instance.如果在mongod实例上运行,则sh.setBalancerState()会出错。

The sh.setBalancerState() method has the following parameter:sh.setBalancerState()方法具有以下参数:

Parameter参数Type类型Description描述
statebooleanSet this to true to enable the balancer and false to disable it.将此设置为true以启用平衡器,将其设置为false以禁用平衡器。
←  sh.reshardCollection()sh.shardCollection() →