Database Manual / Reference / Database Commands / Sharding

balancerStart (database command数据库命令)

Definition定义

balancerStart

Starts the balancer thread. The command does not wait for a balancing round to start.启动平衡器线程。该命令不会等待平衡回合开始。

Tip

In mongosh, this command can also be run through the sh.startBalancer() helper method.mongosh中,此命令也可以通过sh.startBalancer()辅助方法运行。

Helper methods are convenient for mongosh users, but they may not return the same level of information as database commands. 助手方法对mongosh用户来说很方便,但它们可能不会返回与数据库命令相同级别的信息。In cases where the convenience is not needed or the additional return fields are required, use the database command.如果不需要便利性或需要额外的返回字段,请使用database命令。

Starting in MongoDB 6.0.3, automatic chunk splitting is not performed. This is because of balancing policy improvements. Auto-splitting commands still exist, but do not perform an operation.从MongoDB 6.0.3开始,不执行自动块分割。这是因为平衡了政策的改进。自动拆分命令仍然存在,但不执行操作。

In MongoDB versions earlier than 6.1, the command enables auto-splitting for the sharded cluster. To disable auto-splitting when the balancer is enabled, you can use sh.disableAutoSplit().在早于6.1的MongoDB版本中,该命令启用了分片集群的自动拆分。要在启用平衡器时禁用自动拆分,可以使用sh.disableAutoSplit()

Compatibility兼容性

This command is available in deployments hosted in the following environments:此命令在以下环境中托管的部署中可用:

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud:云中MongoDB部署的完全托管服务
  • MongoDB Enterprise: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本
  • MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB:MongoDB的源代码可用、免费使用和自我管理版本

Syntax语法

You can only issue the balancerStart against the admin database on a mongos instance.您只能对mongos实例上的admin数据库发出balancerStart

The command has the following syntax:

db.adminCommand(
{
balancerStart: 1,
maxTimeMS: <number>
}
)

Command Fields命令字段

Field字段Type类型Description描述
balancerStartany任意Any value.任何价值。
maxTimeMSinteger整数

Optional. 可选。Time limit for enabling the balancer.启用平衡器的时间限制。

Defaults to 60000 milliseconds.默认值为60000毫秒。

Example示例

To start the balancer thread, connect to a mongos instance and issue the following command:要启动平衡器线程,请连接到mongos实例并发出以下命令:

db.adminCommand( { balancerStart: 1 } )