Data hole refers to the fact that the size of a table’s data file is larger than its actual data size after frequent update and delete. such as
show dbsSee a library is 400G, only 250G after export and import.
The repairDatabase command compacts all collections in the database. It is identical to running the compact command on each collection individually.
It should be noted that
repairDatabaseThat frees up the disk space that has already been requested, but new disk requests will use the sorted space. Another thing to note is that both commands require extra space, seeDicksusage section. This means that if the disk space is full, the two commands will not be used. However, at this time, you can start againSynchronizing a Slave Node, rebuild the disk data.
If used in replica set
compactIf so, it is best to adopt the rolling method.
The Rolling method is to take one out of the secondary and arrange the disks. Then repeat the above steps on all slave nodes. LastRemove the primary node, and then organize the disks on it. This can avoid the impact of these operations on online services.
usePowerOf2SizesLet MongoDB use disks more effectively under frequent updates and deletions, because each application and release is a power of 2.