MongoDB: reduce file size
I have a small Digital Ocean VPS with MongoDB with 20 GB storage. The database dump is 1.7 GB, but the directory
/var/lib/mongodb occupies about 7 GB disk space. If it goes on like that, I will run out of free space.
MongoDB 3 uses the WiredTiger storage engine, but before that the mmapv1 engine was the default. The mmapv1 has two options to reduce file size but WiredTiger doesn’t support these options :(
So I switched back to mmapv1. Here is my
/etc/mongod.conf file that enables file size reduction:
# mongod.conf # for documentation of all options, see: # http://docs.mongodb.org/manual/reference/configuration-options/ # Where and how to store data. storage: dbPath: /var/lib/mongodb journal: enabled: true engine: mmapv1 mmapv1: preallocDataFiles: false smallFiles: true # wiredTiger: # where to write logging data. systemLog: destination: file logAppend: true path: /var/log/mongodb/mongod.log # network interfaces net: port: 27017 bindIp: 127.0.0.1
smallFiles. Keep in mind that they may have negative impact on the performance. In my case I was just collecting a lot of data and not running out of free space was more important.
/var/lib/mongodb is 4 GB now, not 7 GB.
To figure out if Mongo uses WiredTiger or mmapv1, execute this in the mongo shell: