moveChunk
Definition
moveChunk
- Internal administrative command. Moves chunks betweenshards. Issue the
moveChunk
command viaamongos
instance while using the admin database.Use the following forms:
- db.adminCommand( { moveChunk : <namespace> ,
- find : <query> ,
- to : <string>,
- _secondaryThrottle : <boolean>,
- writeConcern: <document>,
- _waitForDelete : <boolean> } )
Alternatively:
- db.adminCommand( { moveChunk : <namespace> ,
- bounds : <array> ,
- to : <string>,
- _secondaryThrottle : <boolean>,
- writeConcern: <document>,
- _waitForDelete : <boolean> } )
The moveChunk
command has the following fields:
FieldTypeDescriptionmoveChunk
stringThe namespace of the collection where thechunk exists. Specify the collection’s full namespace,including the database name.find
documentAn equality match on the shard key that specifies the shard-key valueof the chunk to move. Specify either the bounds
field or thefind
field but not both. Do not use the find
field toselect chunks in collections that use a hashed shard key.bounds
arrayThe bounds of a specific chunk to move. The array must consist of twodocuments that specify the lower and upper shard key values of a chunkto move. Specify either the bounds
field or the find
field butnot both. Use bounds
to select chunks in collections that use ahashed shard key.to
stringThe name of the destination shard for the chunk._secondaryThrottle
booleanOptional. Starting in MongoDB 3.4, for WiredTiger,defaults to false
.
- If
true
, then by default, each document move during chunkmigration propagates to at least one secondary before the balancerproceeds with the next document. This is equivalent to a writeconcern of{ w: 2 }
.
Use the writeConcern
option to specify a different write concern.
- If
false
, the balancer does not wait for replication to asecondary and instead continues with the next document.
For more information, seeSecondary Throttle.writeConcern
documentOptional. A document that expresses the write concern that the _secondaryThrottle
will use towait for secondaries during the chunk migration.
writeConcern
requires _secondaryThrottle: true
._waitForDelete
booleanOptional. Internal option for testing purposes. The default is false
. If setto true
, the delete phase of a moveChunk
operationblocks.
The value of bounds
takes the form:
- [ { hashedField : <minValue> } ,
- { hashedField : <maxValue> } ]
The chunk migration sectiondescribes how chunks move between shards on MongoDB.
See also
split
, sh.moveChunk()
,sh.splitAt()
, and sh.splitFind()
.
Considerations
Only use the moveChunk
in special circumstancessuch as preparing your sharded cluster for an initialingestion of data, or a large bulk import operation. In most casesallow the balancer to create and balance chunks in sharded clusters.See Create Chunks in a Sharded Cluster for more information.
Behavior
Indexes
Changed in version 3.0.0: In previous versions, moveChunk
would build indexes aspart of the migrations.
moveChunk
requires that all indexes exist on thetarget (i.e. to
) shard before migration and returns an error if arequired index does not exist.
Meta Data Error
moveChunk
returns the following error message if anothermetadata operation is in progress on the chunks
collection:
- errmsg: "The collection's metadata lock is already taken."
If another process, such as a balancer process, changes meta datawhile moveChunk
is running, you may see thiserror. You may retry the moveChunk
operation withoutside effects.