Should I compact a MongoDB database before mongodump/mongorestore?

897 views Asked by At

I have a database that hasn't been compacted in a while so its disk size is much larger than actual data and index sizes. I'll be moving it to another database and would like to know:

  1. would compacting speed up mongodump

  2. does mongorestore rebuild the database in a compact way negating the need to compact

1

There are 1 answers

0
Nikita Chernov On
  1. Compact + dump should be longer than a single dump since compact in the first run will operate on the same non-compact data.

  2. Yes, it rebuilds the database in a compact way and also releases physical disk space. Simple compact will decrease data size only, but disk space still will be allocated by Mongo (you will not be able to use it for other purposes).