When using MongoDB's .stats() function to determine document size, are the values returned in bits or bytes?
Description. Returns statistics that reflect the use state of a single database. The db. stats() method is a wrapper around the dbStats database command.
stats() method is used to return a document that reports on the state of the current database. Syntax: db.stats(scale) Parameters: Name.
Get size of index and data in MongoDB collection with scaling factor. db. user. stats(1024) , is used to get size of data and size of index on user collection in MongoDB.
collection. totalSize() method is used to reports the total size of a collection, including the size of all documents and all indexes on a collection. Returns: The total size in bytes of the data in the collection plus the size of every index on the collection.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With