sh.setBalancerState()
On this page本页内容
Description描述
sh.setBalancerState(state)-
Enables or disables the balancer.启用或禁用平衡器。Starting in MongoDB 6.1, automatic chunk splitting is not performed.从MongoDB 6.1开始,不执行自动区块分割。This is because of balancing policy improvements.这是因为平衡政策的改进。Auto-splitting commands still exist, but do not perform an operation.自动拆分命令仍然存在,但不执行操作。For details, see Balancing Policy Changes.有关详细信息,请参阅平衡策略更改。In MongoDB versions earlier than 6.1,在6.1之前的MongoDB版本中,如果启用平衡器,sh.setBalancerState()also enables auto-splitting if enabling the balancer and disables auto-splitting if disabling the balancer.sh.setBalancerState()也会启用自动拆分,如果禁用平衡器,则会禁用自动拆分。Use使用sh.getBalancerState()to determine if the balancer is currently enabled or disabled andsh.isBalancerRunning()to check its current state.sh.getBalancerState()确定平衡器当前是启用还是禁用,并使用sh.isBalancerRunning()检查其当前状态。Importantmongosh Method
This page documents a
mongoshmethod. This is not the documentation for database commands or language-specific drivers, such as Node.js.For the database command, see the
balancerStartandbalancerStopcommands.For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.
For the legacy
mongoshell documentation, refer to the documentation for the corresponding MongoDB Server release:ImportantYou can only run您只能在sh.setBalancerState()on amongosinstance.mongos实例上运行sh.setBalancerState()。如果在sh.setBalancerState()errors if run onmongodinstance.mongod实例上运行,则会出现sh.setBalancerState()错误。Thesh.setBalancerState()method has the following parameter:sh.setBalancerState()方法具有以下参数:Parameter参数Type类型Description描述stateboolean Set this to将此设置为trueto enable the balancer andfalseto disable it.true可启用平衡器,将其设置为false可禁用平衡器。