在 Ubuntu Box 上壓縮 Mongo 資料庫

預分配。Mongo 在空容器中留出了磁碟空間,因此當需要將某些內容寫入磁碟時,它不必先將位置移除。它通過加倍演算法實現,總是將預先分配的磁碟空間量增加一倍,直到達到 2GB; 然後從其上的每個 prealloc 檔案是 2GB。一旦資料被預先分配,除非你明確告知,否則它不會取消分配。因此可觀察的 MongoDB 空間使用率會自動上升,但不會下降。

關於 Mongo 預分配的一些研究…
reduce-mongodb-database-file-size
mongo-prealloc-files-taking-up-room

// compact the database from within the Mongo shell
db.runCommand( { compact : 'mycollectionname' } )

// repair the database from the command line
mongod --config /usr/local/etc/mongod.conf --repair --repairpath /Volumes/X/mongo_repair --nojournal

// or dump and re-import from the command line
mongodump -d databasename
echo 'db.dropDatabase()' | mongo databasename
mongorestore dump/databasename