I have seen questions about compacting a MongoDB database file and about reusing space freed up by deleting entire documents, but I cannot find any information about whether fields from the documents will free up space for other new documents.
In particular, I have documents representing the results of an operation, containing metadata about this and the possible result of the operation, as well as a large detailed journal. The log is orders of magnitude larger than all other fields. I would like to save other fields, but after a while the logs take up more space than they are worth it, so I would like to delete them, but only if it makes sense to do it!
Will this do what I want? Or do I need to create new documents as copies of old ones, but without a large field and delete old documents?
The basic concept is that MongoDB allocates storage space for your document, which allows this document to grow in place. The difference between the size of the document and the record is called filling. Simple filling reduces the efficiency of moving documents.
As suggested by @NeilLunn, deleting fields from a document will not return this place for writing to a free list. This is also noted in the Record Padding documentation :
, , $unset $pop, . , , compact repairDatabase.
( MongoDB 2.2) :
. MongoDB paddingFactor . , . MongoDB 2.4.
paddingFactor
Power of 2 Sizes. MongoDB 2 (, 4, 8, 16,.. 4 , 1 ). , . MongoDB 2.2 2.4 MongoDB 2.6.
. , , , .
, (.. ). usePowerOf2Sizes , . paddingFactor paddingBytes .
usePowerOf2Sizes
paddingBytes
, , - , , . , . , , , , !, ? , ?
, , - , , . , . , , , , !
, ? , ?
:
repairDatabase
usePowerOf2Sizes , .
, . powerOf2Sizes , .
" ", , , -, , , , - MongoDB.
, , - "". - , , " ", , , , "" , , .
, "" - , , " ", , "", , , , .
, , , . , .
, " " , . , , , , , .
, "" , , , , , . , MongoDB .
, , . , , , .