You can stop moving an unsharded collection by using the
abortMoveCollection command.
About this Task
To stop an in-progress moveCollection operation, run the
abortMoveCollection command on the admin database.
Access Control
If your deployment has access control enabled,
the enableSharding role allows you to run the
abortMoveCollection command.
Steps
Stop moving the collection
To stop moving a collection, run the abortMoveCollection
command. The following example stops the in-progress move of the
app.inventory collection from shard01 to shard02.
db.adminCommand( { abortMoveCollection: "app.inventory" } )
After you run the abortMoveCollection command, the command output
returns ok: 1 and resembles the following:
{ ok: 1, '$clusterTime': { clusterTime: Timestamp( { t: 1726524884, i: 28 } ), signature: { hash: Binary.createFromBase64('AAAAAAAAAAAAAAAAAAAAAAAAAAA=', 0), keyId: Long('0') } }, operationTime: Timestamp({ t: 1726524884, i: 28 }) }
Confirm the move operation was stopped
To confirm the collection wasn't moved to the new shard, use the
$collStats pipeline stage.
The following example shows how to confirm that the app.inventory
collection remains on the same shard:
db.inventory.aggregate( [ { $collStats: {} }, { $project: { "shard": 1 } } ] )
This pipeline stage has output similar to the following:
[ { shard: 'shard01' } ]