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步骤
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 })
}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 以下示例显示了如何确认appinvestory集合保留在同一分片上: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' } ]