Aaron Silverman
Aaron Silverman

Reputation: 22655

Should I compact a MongoDB database before mongodump/mongorestore?

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

Upvotes: 0

Views: 976

Answers (1)

Nikita Chernov
Nikita Chernov

Reputation: 2061

  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).

Upvotes: 3

Related Questions