Database Size Check for Fragmentation/Wasted Space/Index Rebuild

Hi,

The database is an AWS DocumentDB which is am told almost like MongoDB.
I am a total newbie to DocumentDB or MongoDB. Unfortunately, need to check on everything that get send my way :frowning:
So far, no luck getting feedback at re:Post, maybe someone can give some advice here.

One of the developers thinks the database is ‘bloated’, fragmented or has lots of wasted space and maybe is contributing to some performance issue of some sort.

Version and Size information below.

rs0:PRIMARY> db.version()
4.0.0
rs0:PRIMARY> db.runCommand({getEngineVersion: 1})
{
        "engineVersion" : "2.0.10898",
        "ok" : 1,
        "operationTime" : Timestamp(1732071471, 1)
}
rs0:PRIMARY>

rs0:PRIMARY> db.stats()
{
        "db" : "[MyDB]",
        "collections" : 28,
        "objects" : 44452673,
        "storageSize" : 151448076288,
        "indexes" : 135,
        "indexSize" : 242403483648,
        "fileSize" : 393851559936,
        "ok" : 1,
        "operationTime" : Timestamp(1732072484, 1)
}

Is there a quick way to check if there really is some wasted space that may require some reorg of some sort to improve performance in some way? I’ve been doing a lot of reading and browsing around but can’t find what am looking for. At the moment, I am interested in finding out whether there is ‘considerable’ waste of space or fragmentation anywhere or do we need to rebuild indexes but based on what? Had several chapters on index rebuild but can’t quite come up with the conclusion on whether an index rebuild is necessary or not :frowning:

Any guidance will be much appreciated. Thanks in advance.

P.S.: I wish I can get db.stats to show in GB :frowning: Can’t run aws cli commands, can only use mongo/mongosh. I did find db.stats, I will try db.stats with a supplied parameter.

Hi @Edwin_49627

Essentially DocumentDB is not MongoDB. It is an AWS product that provides an api that provides partial compatibilty/coverage with mongoDB clients.

Reclaiming free space from collections shows up from time to time in the forums and solutions have been provided as a cursory search will show. But these will be of no use on DocumentDB as they are MongoDB specific.

ref:
https://www.mongodb.com/resources/compare/documentdb-vs-mongodb

1 Like