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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -