Tag Archives: sum in MongoDB

MongoDB -Get Total datasize of all DB’s

var sum = 0; db.getMongo().getDBs()[“databases”].forEach(function(x) { sum += db.getMongo().getDB(x.name).stats().dataSize }); print(sum ); OR db = db.getSiblingDB(“admin”); dbs = db.runCommand({ “listDatabases”: 1 }).databases; var sum1=0;dbs.forEach(function(database) { sum1+=db.getMongo().getDB(database.name).stats().dataSize }); print(sum1); Advertisements

Posted in MongoDB | Tagged , , | Leave a comment