Docs Menu
Docs Home
/
MongoDB Manual
/ / /

Stop Defragmenting a Sharded Collection

On this page

  • About this Task
  • Before you Begin
  • Procedure
  • Next Steps
  • Learn More

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.

The procedure in this task uses an example sharded collection named ordersShardedCollection in a database named test.

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.

1

Run:

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

When defragmentation stops, the command output returns 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 })
}

You can start defragmentation again at any time. For details, see Start Defragmenting a Sharded Collection.

  • Print shard status, see db.printShardingStatus()

  • Retrieve shard status details, see sh.status()

  • View shard status collection fields, see Sharded Collection

  • See active mongos instances, see Active mongos Instances

  • Monitor shards using MongoDB Atlas, see Review Sharded Clusters

Back

Monitor