Blog Post

MongoDB -Get Size, RowCount, CollectionSize

,

There are two different ways of getting the desired result

The first method is iterating through each collection using for loop and displaying the result

cols = db.getCollectionNames();
for (index = 0; index < cols.length; index++) {
var coll = db.getCollection(cols[index]);
var stats = coll.stats();
print(stats.ns, stats.count, stats.size, stats.totalIndexSize); }

OR

The second method is iterating through each collection using cursor which in turns call function

var stats;db.getCollectionNames().forEach(function(x) { stats=db.getCollection(x).stats(); print(stats.ns, stats.count, stats.size, stats.totalIndexSize); });

getSizeCountCollection

 

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating