Why the mongodb database take more space after removing documents -


before remove data, database takes 25.5g space, has 413562171 documents.

then execute following operating:

db.collectionname.remove( { xxx: "xxx" } )

this operating deletes 165540416 documents , database takes 25.8g.

i confused why takes more space after removing data.

when remove documents, mongodb doesn't free space automatically (it supposes space can reused new documents)

you can free space using repairdatabase command: db.repairdatabase() mongo shell; or mongod --repair (mongod should not running when use way) https://docs.mongodb.com/v3.2/reference/command/repairdatabase/

please, take account repairdatabase requires free disk space equal size of current data set plus 2 gigabytes, , obtains global write lock, block other operations until has completed

little addition:

if use wiredtiger storage engine can use compact command instead repairdatabase

https://docs.mongodb.com/manual/reference/command/compact/

the wiredtiger storage engine default storage engine starting in mongodb 3.2


Comments