Calculating Collection Size
We can get the size of a collections by using the shell’s functions
- db.collection.dataSize() : Returns data size in bytes for the collection.
- db.collection.storageSize() : Returns allocation size in bytes, including unused space.
- db.collection.totalSize() : Returns the data size plus the index size in bytes.
Calculating Size of All Collections
>cols = db.getCollectionNames();
// Iterate through each collection.
> cols.forEach(function(col) {
print (col +’-‘+ db[col].totalSize());
});