Docs HomeMongoDB Manual

sh.startBalancer()

On this page本页内容

Definition定义

sh.startBalancer(timeout, interval)

Changed in version 6.1.6.1版更改。

Starts the balancer in a sharded cluster.在分片集群中启动平衡器。

Starting in MongoDB 6.1, automatic chunk splitting is not performed. This is because of balancing policy improvements. 从MongoDB 6.1开始,不执行自动区块分割。这是因为平衡政策的改进。Auto-splitting commands still exist, but do not perform an operation. 自动拆分命令仍然存在,但不执行操作。For details, see Balancing Policy Changes.有关详细信息,请参阅平衡策略更改

In MongoDB versions earlier than 6.1, sh.startBalancer() also enables auto-splitting for the sharded cluster.在6.1之前的MongoDB版本中,sh.startBalancer()还支持对分片集群进行自动拆分。

Important

mongosh Method

This page documents a mongosh method. This is not the documentation for database commands or language-specific drivers, such as Node.js.

For the database command, see the balancerStart command.

For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.

For the legacy mongo shell documentation, refer to the documentation for the corresponding MongoDB Server release:

mongo shell v4.4

The method can take the following options:该方法可以采用以下选项:

Parameter参数Type类型Description描述
timeoutintegerOptional.可选的。Time limit for enabling the balancer.启用平衡器的时间限制。
Defaults to 60000 milliseconds. 默认值为60000毫秒。
intervalintegerOptional.可选的。The frequency (in milliseconds) at which to check if a balancing round has started.检查是否已开始平衡循环的频率(以毫秒为单位)。

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

Behavior行为

The mongosh shell method sh.startBalancer() is a wrapper around the balancerStart command. mongosh shell方法sh.startBalancer()balancerStart命令的包装器。As such, the method does not wait for balancing to start.因此,该方法不等待平衡开始。

In earlier versions, the method waited for the balancing to start.在早期版本中,该方法等待平衡开始。