I have a database in MongoDB, called dump. Currently, it reached 6GB in my server. I decided to delete 90% of data in this database to reduce the disk space it occupied. But after doing that its size is still 6GB, while the true storage size is only 250MB.
I guess this is the design of MongoDB? Is there any convinient way to reduce its size? Thank in advance.
fileSize is larger than storageSize because it includes index extents and yet-unused space in data files. While fileSize does decrease when you delete a database, fileSize does not decrease as you remove collections, documents or indexes.
FYI: MongoDB does not release disk space after you delete a document, instead, it will reuse that space for future documents, hence the storageSize being bigger than dataSize .
collection. remove() — MongoDB Manual.
Try (source):
$ mongo mydb
> db.repairDatabase()
To compress the data files, you can run either start up MongoDB with mongod --repair
, or connect to the database through the shell and run db.repairDatabase()
.
There's also a new compact command scheduled for v1.9 that will do in-place compaction.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With