What are the sizes returned by `show collections`?

Jérôme picture Jérôme · Nov 25, 2016 · Viewed 10.6k times · Source

Edit: This question is not about vanilla MongoDB's show collections but about mongo-hacker. See accepted answer and comments.


Using Mongo DB 3.2 + WiredTiger, show collections displays two sizes: s1 / s2.

show collections
coll_1               → 10.361MB / 1.289MB
coll_2               →  0.000MB / 0.004MB
coll_3               →  0.000MB / 0.016MB
coll_4               →  0.001MB / 0.031MB

My guess is these are:

  • s1: total size of the documents in the database
  • s2: size of the database on disk (documents + indexes) after compression

Is this correct? I couldn't find any reference in the docs.

Answer

kalaivani picture kalaivani · Nov 26, 2018

You can use the below query to get the size of each collections:

var collectionNames = db.getCollectionNames(), stats = [];
collectionNames.forEach(function (n) { stats.push(db[n].stats()); });
for (var c in stats) {
    print(stats[c]['ns'] + ": " + stats[c]['size'] + " (" + stats[c]['storageSize'] + ")");
}