moveRange
On this page
Definition
moveRange- 
Moves ranges between shards. Run the
moveRangecommand with amongosinstance while using the admin database. 
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>, max: <max key of the range to move>, // optional forceJumbo: <bool>, // optional waitForDelete: <bool>, // optional writeConcern: <write concern>, // optional secondaryThrottle: <bool> // optional } )
Command Fields
The command takes the following fields:
| Field | Type | Description | 
|---|---|---|
toShard | string | ID of the recipient shard. | 
min | key | Minimum key of the range to move. | 
max | key | Optional. Maximum key of the range to move. If you do not specify max, given a chunk C including the shard key min, max is determined in the following way:
  | 
| forceJumbo | boolean | Optional. Flag that determines if the command can move a range that is too large to migrate. The range may or may not be labeled as jumbo. 
 false.
 | 
writeConcern | document | Optional. Document with the write concern. The default is w: majority.
 | 
secondaryThrottle | boolean | Optional.
  | 
The range migration section describes how ranges move between shards on MongoDB.
Considerations
Only use the moveRange in scenarios like:
- 
an initial ingestion of data
 - 
a large bulk import operation
 
Allow the balancer to create and balance ranges in sharded clusters in most cases.
Tip
See also:
Examples
The following examples use a collection with:
- 
Shard key
x - 
Configured chunk size of 128MB
 - 
A chunk with boundaries:
[x: 0, x: 100) 
Specify both min and max
The following table lists the results of setting min and max to various values:
min | max | Result | 
|---|---|---|
0 | 100 | Moves all the documents in the range to the recipient shard. | 
10 | 30 | Creates three sub-ranges:
 [x: 10, x: 30) to the recipient shard.
 | 
0 | 20 | Creates two sub-ranges:
 [x: 0, x: 20) to the recipient shard.
 | 
40 | 100 | Creates two sub-ranges:
 [x: 40, x: 100) to the recipient shard.
 | 
Specify min but not max
The following table lists the results of setting min to various values:
min | Amount of Data in Key Range | Result | 
|---|---|---|
0 | Less than 128 MB contained between keys x: 0 and x: 100. | Moves all the documents in the range to the recipient shard. | 
10 | Less than 128 MB contained between keys x: 0 and x: 100. | Creates two sub-ranges:
 [x: 10, x: 100) to the recipient shard.
 | 
10 | 128 MB contained between keys x: 10 and x: 30. | Creates three sub-ranges:
 [x: 10, x: 30) to the recipient shard.
 |