0

I have MongoDB database of several millions documents. To reduce it's size, I'm going to make a task to delete some fields of each document when they will expire, periodically (but not documents themself).

I'm not sure how the engine stores the data on disk, so will MongoDB compact database on disk, defragment data? Is that the right thing to do with MongoDB?

I am using MongoDB 3.2.4 with WiredTiger.

P.S. I am not asking about releasing space to OS, I am asking about internal MongoDB storage of data, is it prone to be fragmented? Should I do something additional to defragment it?

Antigluk
  • 1,176
  • 2
  • 11
  • 30
  • Despite your P.S, it's exactly what you are asking and it has the same conclusions anyway, therefore ANY variation is duplicated by the existing answers. It's also wildly off-topic as a non-programming question as you are asking about DBA centric issues that need not concern a programmer. And this is a site for programming questions only. If you want to debate it, then please take it up on [dba.stackexchange.com](https://dba.stackexchange.com) where more like minded DBA type persons might have a different point of view. – Neil Lunn Jun 06 '18 at 12:06
  • Storage engines change. If you rely on specific behaviour of particular version, you may need to change your architecture when you upgrade the db. v3.2 is going to die in few month. It would have more sense to use snappy or zlib compression if you care about disc space to such degree. – Alex Blex Jun 06 '18 at 12:36
  • You're right. But the question is about the design, on large DB sizes and hundreds of thousands of documents creating and rewriting every day it will quickly become a problem. Does that makes sense to remove parts of document or better delete and re-create new without that field? Will I end up with highly fragmented data or DB can care about it? That's - the question! It can even turn out that using MongoDB is not the right choice here – Antigluk Jun 06 '18 at 12:39
  • Will it? I smells like you tilting at windmills. WT copies on write anyway. It's not mmap. Compact the collection time to time and you will be fine. – Alex Blex Jun 06 '18 at 13:19

0 Answers0