moveRange
Definition
moveRange
New in version 6.0.
Moves ranges between shards. Run the
moveRange
command with amongos
instance 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>, // conditional max: <max key of the range to move>, // conditional 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. Required if you don't specify
If you do not specify
|
max | key | Maximum key of the range to move. Required if you don't specify
If you do not specify
|
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.
The default is | |
writeConcern | document | |
secondaryThrottle | boolean | Optional.
For more information, see Secondary Throttle. |
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.
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:
Moves all the documents in |
0 | 20 | Creates two sub-ranges:
Moves all the documents in |
40 | 100 | Creates two sub-ranges:
Moves all the documents in |
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:
Moves all documents in |
10 | 128 MB contained between keys x: 10 and x: 30 . | Creates three sub-ranges:
Moves all documents in |
Specify max
but not min
The following table lists the results of setting max
to various
values:
max | Amount of Data in Key Range | Result |
---|---|---|
100 | 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:
Moves all documents in |
30 | 128 MB contained between keys x: 10 and x: 30 . | Creates three sub-ranges:
Moves all documents in |