Does the MongoDB stats() function return bits or bytes?
Running the collStats command - db.collection.stats() - returns all sizes in bytes, e.g.
> db.foo.stats()
{
"size" : 715578011834, // total size (bytes)
"avgObjSize" : 2862, // average size (bytes)
}
However, if you want the results in another unit then you can also pass in a scale
argument.
For example, to get the results in KB:
> db.foo.stats(1024)
{
"size" : 698806652, // total size (KB)
"avgObjSize" : 2, // average size (KB)
}
Or for MB:
> db.foo.stats(1024 * 1024)
{
"size" : 682428, // total size (MB)
"avgObjSize" : 0, // average size (MB)
}
Bytes of course. Unless you pass in a scale as optional argument.
db.stats() in Bytes
db.stats(1024) in KB
db.stats(1024*1024) in MB
db.stats(1024*1024*1024) in GB
By default, the .stats()
function returns in byte format. You need to pass the argument to see in a different format.
Results in Byte:
db.stats()
Results in KB:
db.stats(1024)
Results in MB:
db.stats(1024*1024)
Results in GB:
db.stats(1024*1024*1024)