Database Manual / Sharding / Data Partitioning / Moveable Collections

Stop Moving a Collection停止移动集合

You can stop moving an unsharded collection by using the abortMoveCollection command.您可以使用abortMoveCollection命令停止移动未记录的集合。

About this Task关于此任务

To stop an in-progress moveCollection operation, run the abortMoveCollection command on the admin database.要停止正在进行的moveCollection操作,请在管理数据库上运行abortMoveCollection命令。

Access Control访问控制

If your deployment has access control enabled, the enableSharding role allows you to run the abortMoveCollection command.如果部署启用了访问控制,则enableSharding角色允许您运行abortMoveCollection命令。

Steps步骤

1

Stop moving the collection停止移动集合

To stop moving a collection, run the abortMoveCollection command. 要停止移动集合,请运行abortMoveCollection命令。The following example stops the in-progress move of the app.inventory collection from shard01 to shard02.以下示例停止正在进行的将app.inventory集合从shard01移动到shard02的操作。

db.adminCommand( {
abortMoveCollection: "app.inventory"
} )

After you run the abortMoveCollection command, the command output returns ok: 1 and resembles the following:运行abortMoveCollection命令后,命令输出返回ok: 1,类似于以下内容:

{
ok: 1,
'$clusterTime': {
clusterTime: Timestamp( { t: 1726524884, i: 28 } ),
signature: {
hash: Binary.createFromBase64('AAAAAAAAAAAAAAAAAAAAAAAAAAA=', 0),
keyId: Long('0')
}
},
operationTime: Timestamp({ t: 1726524884, i: 28 })
}
2

Confirm the move operation was stopped确认移动操作已停止

To confirm the collection wasn't moved to the new shard, use the $collStats pipeline stage.要确认集合没有移动到新的分片,请使用$collStats管道阶段。

The following example shows how to confirm that the app.inventory collection remains on the same shard:以下示例显示了如何确认appinvestory集合保留在同一分片上:

db.inventory.aggregate( [
{ $collStats: {} },
{ $project: { "shard": 1 } }
] )

This pipeline stage has output similar to the following:该管道阶段的输出类似于以下内容:

[ { shard: 'shard01' } ]

Learn More了解更多