0

I have some big mongo databases and when I delete data to free up space the data is removed but the space used is the same. Is there a way to compress the data? I know with MS ACCESS a similar need exists to compress to reduce the space.

Trevor Oakley
  • 438
  • 5
  • 17

1 Answers1

0

Found it - db.repairDatabase()

Trevor Oakley
  • 438
  • 5
  • 17
  • Yes, that will rewrite the sectors of the db files and so "compressing it" (though that is not what it does, of course). It is good to note that this is not always a good thing, especially if you want performance in production. MongoDB is keeping the space so it can be used again for new documents without needing to go through all the steps of reallocation etc etc – Sammaye Nov 07 '15 at 14:33
  • Expanding on @Sammaye : `db.repairDatabase()` is not an operation to be taken lightly. It takes a **global** lock, effectively preventing **all** operations. Furthermore, it requires `data size + 2GB`, which means you need quite some space over provisioned which could be used for the DB the first place. And it can take quite some, time, especially since it recreates all indices. If you rely on it in production, you are going to face ***severe*** problems. Imho, the need of using it is a sure sign of bad cluster design. – Markus W Mahlberg Nov 07 '15 at 17:18