Definition
- moveRange
- New in version 6.0. - Moves ranges between shards. Run the - moveRangecommand with a- mongosinstance while using the admin database.- Tip- In - mongosh, this command can also be run through the- sh.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.
Compatibility
This command is available in deployments hosted in the following environments:
- MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud 
Note
This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.
- MongoDB Enterprise: The subscription-based, self-managed version of MongoDB 
- MongoDB Community: The source-available, free-to-use, and self-managed version of 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.
Command Fields
The command takes the following fields:
| Field | Type | Description | 
|---|---|---|
| 
 | string | ID of the recipient shard. | 
| 
 | key | Minimum key of the range to move. Required if you don't specify
 If you do not specify  
 | 
| 
 | 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  WARNING: The  This option causes the shard to migrate chunks even when they are larger than the configured chunk size. The collection remains unavailable for writes for the duration of the migration. To migrate these large chunks without this long blocking period, see Balance Ranges that Exceed Size Limit instead. | |
| 
 | document | |
| 
 | 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 | 
|---|---|---|
| 
 | 
 | Moves all the documents in the range to the recipient shard. | 
| 
 | 
 | Creates three sub-ranges: 
 Moves all the documents in  | 
| 
 | 
 | Creates two sub-ranges: 
 Moves all the documents in  | 
| 
 | 
 | 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 | 
|---|---|---|
| 
 | Less than 128 MB contained between keys  | Moves all the documents in the range to the recipient shard. | 
| 
 | Less than 128 MB contained between keys  | Creates two sub-ranges: 
 Moves all documents in  | 
| 
 | 128 MB contained between keys  | 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 | 
|---|---|---|
| 
 | Less than 128 MB contained between keys  | Moves all the documents in the range to the recipient shard. | 
| 
 | Less than 128 MB contained between keys  | Creates two sub-ranges: 
 Moves all documents in  | 
| 
 | 128 MB contained between keys  | Creates three sub-ranges: 
 Moves all documents in  |