Getting actual storage size

Hi and good day,

I’m kind of new with MongoDB , i have noticed on version 4 and higher , storage size is smaller than the datasize as shown with db.stats command. i found out that it is because of the Wiredtiger engine compression being done on the storage size…

My question is, Is it possible to get the actual size of the storage without disabling the engine ? I’m using it for our reporting of database status.

From the mongo shell.

Total size on disk (bytes):
db.adminCommand('listDatabases').totalSize

Data Size and Size on Disk for each Database (GiB) (Does not include Indexes):

db.adminCommand('listDatabases').databases.forEach(
  function(x){
    d = db.getSiblingDB(x.name).stats(1024**3); 
    print(tojson(
      {
        "db": d.db, 
        "size": d.dataSize,
         "sizeOnDisk": d.storageSize
      }
    ))
  }
)
1 Like

Thanks for the feedback , will try this out and revert back :slight_smile:

hi chris , i’ve done the said above and compared the result from db.status command , i think its also the same result. storage compression is still applied on the storage size.

What are you asking for in particular?

The snippet I provided gives both Data Size and Storage Size.

yes the script provides the storage and data size but the storage size i’m getting is compressed base from my comparison with the stats provided using db.stats command.

is there a way to get the storage size that is uncompressed?

The uncompressed size is the data size.

1 Like