Definition定义
moveRangeNew in version 6.0.在版本6.0中新增。Moves ranges between shards. Run the在分片之间移动范围。在使用管理数据库时,使用moveRangecommand with amongosinstance while using the admin database.mongos实例运行moveRange命令。Tip
In在mongosh, this command can also be run through thesh.moveRange()helper method.mongosh中,此命令也可以通过sh.moveRange()辅助方法运行。Helper methods are convenient for助手方法对mongoshusers, 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.如果不需要便利性或需要额外的返回字段,请使用数据库命令。
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部署的完全托管服务
Note
This command is supported in all MongoDB Atlas clusters. 所有MongoDB Atlas集群都支持此命令。For information on Atlas support for all commands, see Unsupported Commands.有关Atlas支持所有命令的信息,请参阅不支持的命令。
- 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语法
The command has the following syntax:该命令具有以下语法:
db.adminCommand(
{
moveRange: <namespace>,
toShard: <ID of the recipient shard>,
min: <min key of the range to move>, // conditional
max: <max key of the range to move>, // conditional
forceJumbo: <bool>, // optional
writeConcern: <write concern>, // optional
secondaryThrottle: <bool> // optional
}
)
Note
Use the 使用listShards command to retrieve the ID of the recipient shard.listShards命令检索收件人分片的ID。
Command Fields命令字段
The command takes the following fields:该命令包含以下字段:
toShard | ||
min | key |
|
max | key |
|
forceJumbo |
| |
writeConcern |
| |
secondaryThrottle |
|
The range migration section describes how ranges move between shards on MongoDB.范围迁移部分描述了范围如何在MongoDB上的分片之间移动。
Considerations注意事项
Only use the 仅在以下场景中使用moveRange in scenarios like:moveRange:
an initial ingestion of data初次摄取数据a large bulk import operation大宗进口业务
Allow the balancer to create and balance ranges in sharded clusters in most cases.在大多数情况下,允许平衡器在分片集群中创建和平衡范围。
Examples示例
The following examples use a collection with:以下示例使用集合:
Shard key分片键xxConfigured chunk size of 128MB配置的块大小为128MBA chunk with boundaries:有边界的块:[x: 0, x: 100)
Specify both min and max指定min和max
min and maxThe following table lists the results of setting 下表列出了将min and max to various values:min和max设置为各种值的结果:
min | max | |
|---|---|---|
0 | 100 | |
10 | 30 |
|
0 | 20 |
|
40 | 100 |
|
Specify min but not max指定min,但不指定max
min but not maxThe following table lists the results of setting 下表列出了将min to various values:min设置为各种值的结果:
min | ||
|---|---|---|
0 | x: 0 and x: 100.x:0和x:100之间包含的空间小于128 MB。 | |
10 | x: 0 and x: 100.x:0和x:100之间包含的空间小于128 MB。 |
|
10 | x: 10 and x: 30.x:10和x:30之间包含128 MB。 |
|
Specify max but not min指定max,但不指定min
max but not minThe following table lists the results of setting 下表列出了将max to various values:max设置为各种值的结果:
max | ||
|---|---|---|
100 | x: 0 and x: 100.x:0和x:100之间包含的空间小于128 MB。 | |
10 | x: 0 and x: 100.x:0和x:100之间包含的空间小于128 MB。 |
|
30 | x: 10 and x: 30.x:10和x:30之间包含128 MB。 |
|