Skip to main content

Compact the MongoDB folder

This section provides steps on how to reduce the MongoDB folder size in GravityZone.

In some situations when many systems are created and deleted, in a VMware environment, the mongod folder size can increase from 6 GB to 20 GB. To reclaim lost disk space, repairDatabase can be used.

repairDatabase reduces the total size of the data files on disk. It also recreates all indexes in the database.

repairDatabase for data recovery should not be used unless there is no other option. If there is no corruption and there is enough free space, then repairDatabase is the appropriate and the only way to reclaim disk space. However, before proceeding with the procedure, a snapshot / backup is recommended.

  • Use the mongo shell to run the command, as above.

  • Use the db.repairDatabase() in the mongo shell.

  • Run mongod directly from your system’s shell. Make sure that mongod isn’t already running, and that you invoke mongod as a user that has access to MongoDB’s data files. Run as:

    mongod --repair

    To add a repair path:

    mongod --repair --repairpath /opt/vol2/data