db.collection.stats()
Response :
"count" : 20696445,
"size" : NumberLong("1478263842661"),
"storageSize" : 334732324864,
"totalIndexSize" : 676327424,
"indexSizes" : {
"_id_" : 377094144,
"leadID_1" : 128049152,
"leadID_hashed" : 171184128
},
"avgObjSize" : 71425.97884134208
My actual disk size is matched with storageSize. So what is the size and other keys.
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.
MongoDB has a command db. stats() that can provide insights into the storage statistics of a MongoDB instance. dataSize : The total size in bytes of the uncompressed data held in this database. storageSize : The total amount of disk space allocated to all collections in the database.
Count up the total number of characters in the field names of a document, and call this number a. Add one to a for each field in order to account for the terminating character. Let the result be b. Multiply b by the number of documents in the collection, and let the result be denoted by c.
You haven't mentioned the version of MongoDB server you are using but given the size
of your data is much larger than the storageSize
on disk, I'm assuming you are using the WiredTiger storage engine which compresses data and indexes by default. The WiredTiger storage engine was first available as an option in the MongoDB 3.0 production series and became the default storage engine for new deployments in MongoDB 3.2+.
In your example output it looks like you have 1.4TB of uncompressed data
which is currently occupying 334GB on disk (the storageSize
value). Storage space used by indexes for this collection is reported separately under indexSizes
and summed up as totalIndexSize
.
The output of collection.stats()
will vary depending on your MongoDB server version and configured storage engine, but is generally described in the MongoDB manual as part of the output of the collStats
command which is called by the db.collection.stats()
shell helper.
Note: MongoDB documentation is versioned so you should always make sure you are referencing documentation that matches your release series of MongoDB (i.e. 3.2, 3.4, ...). Default documentation links will point to the current production release.
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