How to get fragmentation stats in mongo/wiredtiger mongo version 4.4

Is there a way to get fragmentation stats in mongo/wiredtiger ?

mongo version: 4.4

Hi @Sameer_Kattel

There’s no literal fragmentation stats in WiredTiger, but you can get some idea by looking at “file bytes available for reuse” and compare it with “file size in bytes” from db.collection.stats() output.

Basically WiredTiger will try to reuse space in “bytes available for reuse” first before extending the file when inserting new documents, and will truncate the file automatically in certain circumstances. This is because WiredTiger assumes you’ll have more data over time and not less, so it expects to be able to reuse those space in the future.

Best regards
Kevin

2 Likes