Docs HomeMongoDB Manual

Modify Range Size in a Sharded Cluster修改分片群集中的范围大小

The default range size for a sharded cluster is 128 megabytes. 分片集群的默认范围大小为128兆字节。This default range size works well for most deployments; however, if you notice that automatic migrations use more I/O than your hardware can handle, you may want to reduce the range size. 此默认范围大小适用于大多数部署;但是,如果您注意到自动迁移使用的I/O比硬件所能处理的要多,则可能需要减小范围大小。A small range size leads to more rapid and frequent migrations. The allowed size is between 1 and 1024 megabytes, inclusive.较小的范围大小会导致更快速、更频繁的迁移。允许的大小介于1到1024兆字节之间(包括1和1024兆字节)。

To modify the range size, use the following procedure:要修改范围大小,请使用以下步骤:

  1. Connect to any mongos in the cluster using mongosh.使用mongosh连接到集群中的任何mongos
  2. Issue the following command to switch to the Config Database:发出以下命令以切换到配置数据库

    use config
  3. Issue the following command to store the global range size configuration value:发出以下命令以存储全局范围大小配置值:

    db.settings.updateOne(
    { _id: "chunksize" },
    { $set: { _id: "chunksize", value: <sizeInMB> } },
    { upsert: true }
    )

The allowed range size is between 1 and 1024 megabytes, inclusive.允许的范围大小介于1到1024兆字节之间(包括1和1024兆字节)。

To set the chunk size for a specific collection, see configureCollectionBalancing.要设置特定集合的区块大小,请参阅configureCollectionBalancing