Database Manual / Sharding / Reference / Defragment Sharded Collections

Stop Defragmenting a Sharded Collection停止分片化集合

Typically, you should use a shard balancing window to specify when the balancer runs instead of manually starting and stopping defragmentation.通常,您应该使用分片平衡窗口来指定平衡器何时运行,而不是手动启动和停止分片整理。

To manually stop defragmenting a sharded collection, use the configureCollectionBalancing command with the defragmentCollection option set to false.要手动停止对分片集合进行分片整理,请使用configureCollectionBalancing命令,并将defragmentCollection选项设置为false

About this Task关于此任务

The procedure in this task uses an example sharded collection named ordersShardedCollection in a database named test.此任务中的过程在名为test的数据库中使用名为ordersShardedCollection的示例分片集合。

You can use your own sharded collection and database in the procedure.您可以在过程中使用自己的分片集合和数据库。

If you stop defragmenting a collection before defragmentation is complete, the collection is in a partially defragmented state and operates as usual. To resume defragmentation, restart the process.如果在分片整理完成之前停止对集合进行分片整理,则该集合处于部分分片整理状态,并照常运行。要恢复分片整理,请重新启动该进程。

Before you Begin开始之前

Procedure过程

1

Stop defragmenting the collection停止对集合进行分片整理

Run:运行:

db.adminCommand(
{
configureCollectionBalancing: "test.ordersShardedCollection",
defragmentCollection: false
}
)
2

Ensure defragmentation stopped确保分片整理已停止

When defragmentation stops, the command output returns ok: 1:当分片整理停止时,命令输出返回ok: 1

{
ok: 1,
'$clusterTime': {
clusterTime: Timestamp({ t: 1678834337, i: 1 }),
signature: {
hash: Binary(Buffer.from("0000000000000000000000000000000000000000", "hex"), 0),
keyId: Long("0")
}
},
operationTime: Timestamp({ t: 1678834337, i: 1 })
}

Next Steps后续步骤

You can start defragmentation again at any time. For details, see Start Defragmenting a Sharded Collection.您可以随时重新开始分片整理。有关详细信息,请参阅开始对分片集合进行分片整理

Learn More了解更多