定义
moveRange6.0版本新增。
Moves ranges between shards. Run the
moveRangecommand with amongosinstance while using the admin database.提示
In
mongosh, this command can also be run through thesh.moveRange()helper method.Helper methods are convenient for
mongoshusers, but they may not return the same level of information as database commands. In cases where the convenience is not needed or the additional return fields are required, use the database command.
兼容性
此命令可用于以下环境中托管的部署:
- MongoDB Atlas:用于云中 MongoDB 部署的完全托管服务
注意
所有 MongoDB Atlas 集群都支持此命令。有关 Atlas 对所有命令的支持的信息,请参阅不支持的命令。
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
语法
该命令具有以下语法:
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 } )
命令字段
该命令接受以下字段:
字段 | 类型 | 说明 |
|---|---|---|
| 字符串 | 接收分片的 ID。 |
| key | 要移动范围的最小键。 如果不指定 如果未指定
|
| key | 要移动范围的最大键。 如果不指定 如果不指定
|
布尔 | 可选。 确定命令是否可以移动过大而无法迁移的范围的标志。 该范围可能会也可能不会标记为jumbo。
默认为 警告: 附带 此选项会导致分片迁移数据段,即使数据段大于配置的数据块大小。 在迁移期间,该集合仍然不可写入。 要在没有这么长的阻塞期的情况下迁移这些大数据段,请参阅平衡超出大小限制的范围。 | |
| 文档 | |
| 布尔 | 可选。
有关更多信息,请参阅辅助限制。 |
范围迁移部分描述了范围如何在 MongoDB 上的分片之间移动。
Considerations
Only use the moveRange in scenarios like:
初始数据摄取
大批量导入操作
在大多数情况下,允许负载均衡器在分片集群中创建和平衡范围。
示例
以下示例使用具有以下内容的collection:
片键
x已配置数据块大小为 128 MB
有边界的数据块:
[x: 0, x: 100)
同时指定min 和max
下表列出将min和max设置为各种值的结果:
min | max | 结果 |
|---|---|---|
|
| 将范围内的所有文档移至接收分片。 |
|
| 创建三个子范围:
将 |
|
| 创建两个子范围:
将 |
|
| 创建两个子范围:
将 |
指定 min 但不指定 max
下表列出了将min设置为各种值的结果:
min | 键范围内的数据量 | 结果 |
|---|---|---|
| 键 | 将范围内的所有文档移至接收分片。 |
| 键 | 创建两个子范围:
将 |
| 键 | 创建三个子范围:
将 |
指定 max 但不指定 min
下表列出了将max设置为各种值的结果:
max | 键范围内的数据量 | 结果 |
|---|---|---|
| 键 | 将范围内的所有文档移至接收分片。 |
| 键 | 创建两个子范围:
将 |
| 键 | 创建三个子范围:
将 |