2. Why are the files in my data directory larger than the data in my database?
2.1 ...(省略3节,关于预分配空间、oplog、journal)
2.2 Empty records
MongoDB maintains lists of empty records in data files as it deletes documents and collections. MongoDB can reuse this space, but will not, by default, return this space to the operating system.
To allow MongoDB to more effectively reuse the space, you can de-fragment your data. To de-fragment, use the compact command. The compact requires up to 2 gigabytes of extra disk space to run. Do not use compact if you are critically low on disk space. For more information on its behavior and other considerations, see compact.
compact only removes fragmentation from MongoDB data files within a collection and does not return any disk space to the operating system. To return disk space to the operating system, see How do I reclaim disk space?.
3. How do I reclaim disk space?
The following provides some options to consider when reclaiming disk space. NOTE
You do not need to reclaim disk space for MongoDB to reuse freed space. See Empty records for information on reuse of freed space.
3.1 repairDatabase
You can use repairDatabase on a database to rebuilds the database, de-fragmenting the associated storage in the process.
repairDatabase requires free disk space equal to the> WARNING
Do not use repairDatabase if you are critically low on disk space.
repairDatabase will block all other operations and may take a long time to complete.
You can only run repairDatabase on a standalone mongod instance.
You can also run the repairDatabase operation for all databases on the server by restarting your mongod standalone instance with the --repair and --repairpath options. All databases on the server will be unavailable during this operation.