There is no need to export and then import, using repairDatabase 或者 compact will compress the data. But they have an impact on performance during operation.
The repairDatabase command compacts all collections in the database. It is identical to running the compact command on each collection inpidually.
It should be noted that compact不会像repairDatabasethis will release the disk space that has been applied for, but new disk requests will use the organized space. Another thing to note is that both commands require additional space, see the dick usage section. This means that if the disk space is full, these two commands will not be used. However, at this time, a slave node can be resynchronized and the disk data can be reconstructed.
If you use repairDatabase或者compact in a replica set, it is best to use the rolling method.
The method of rolling is to first take out a secondary node and defragment the disk. Then repeat the above steps on all slave nodes. Finally, step down primary and defragment the disk on it. This can avoid the impact of these operations on online services.
Recommended to use usePowerOf2Sizes allows MongoDB to use the disk more efficiently under frequent updates and deletions, because each application and release is a power of 2 in size.
There is no need to export and then import, using
repairDatabase
或者compact
will compress the data. But they have an impact on performance during operation.It should be noted that
compact
不会像repairDatabase
this will release the disk space that has been applied for, but new disk requests will use the organized space. Another thing to note is that both commands require additional space, see the dick usage section. This means that if the disk space is full, these two commands will not be used. However, at this time, a slave node can be resynchronized and the disk data can be reconstructed.If you use
repairDatabase
或者compact
in a replica set, it is best to use the rolling method. The method of rolling is to first take out a secondary node and defragment the disk. Then repeat the above steps on all slave nodes. Finally, step down primary and defragment the disk on it. This can avoid the impact of these operations on online services.Recommended to use
usePowerOf2Sizes
allows MongoDB to use the disk more efficiently under frequent updates and deletions, because each application and release is a power of 2 in size.