skip to content
Alvin Lucillo

Running compact on a primary replica

/ 1 min read

It is advisable to perform compact first on secondary replicas because a primary replica receives both write and read operations, so performing a resource-intensive operation on that replica might cause service degredation.

db.runCommand({ compact: "events", dryRun: true })
MongoServerError[IllegalOperation]: will not run compact on an active replica set primary as this will slow down other running operations. use force:true to force