Let’s Talk about MongoDB’s Compact Command

Why Use the Compact Command

The Remove and Drop Commands and How They Compare with the Compact Command

How the Compact Command Affects Write Performance

How the Compact Command Works

How Much Space Is Reclaimed by the Compact Command

mymongo:PRIMARY> db.coll.stats().wiredTiger["block-manager"]["file bytes available for reuse"]
5033984

What to Do Before You Run the Compact Command

// compact somedb.somecollection
use somedb
db.runCommnd({compact: "somecollection"})
// compact oplog,execute the force option on the copy set primary
use local
db.runCommnd({compact: "somecollection", force: true})

Original Source

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store