Запуск
$ docker exec -it agis-mongo-db mongo > show dbs > use zander > show collectionsСтатистика вариант 1
var mgo = new Mongo() function getReadableFileSizeString(fileSizeInBytes) { var i = -1; var byteUnits = [' kB', ' MB', ' GB', ' TB', 'PB', 'EB', 'ZB', 'YB']; do { fileSizeInBytes = fileSizeInBytes / 1024; i++; } while (fileSizeInBytes > 1024); return Math.max(fileSizeInBytes, 0.1).toFixed(1) + byteUnits[i]; }; function getStatsFor(db){ var collectionNames = db.getCollectionNames(), stats = []; collectionNames.forEach(function (n) { stats.push(db.getCollection(n).stats()); }); stats = stats.sort(function(a, b) { return b['size'] - a['size']; }); for (var c in stats) { print(stats[c]['ns'] + ": " + getReadableFileSizeString(stats[c]['size']) + " (" + getReadableFileSizeString(stats[c]['storageSize']) + ")"); } } function getAllStats(){ mgo.getDBNames().forEach(function(name){ var db = mgo.getDB(name); print('\n '+db+'\n'); getStatsFor(db) }) } getAllStats()Результат
lb-identity-service lb-identity-service.identity-role: 67.0 kB (40.0 kB) lb-identity-service.identity-user: 2.3 kB (32.0 kB) lb-identity-service.identity-useridentity-role: 0.5 kB (32.0 kB) local local.startup_log: 104.7 kB (52.0 kB) zander zander.values201: 26.6 GB (6.2 GB) zander.objectValues201: 24.0 GB (6.7 GB) zander.message201: 21.5 GB (5.4 GB) zander.logg201: 12.2 GB (3.3 GB) zander.fs.chunks: 9.2 GB (9.1 GB) zander.odataOpuConsumptionReading: 1.2 GB (278.7 MB) zander.values: 1003.8 MB (253.3 MB)Статистика вариант 2
function getCollectionSizes() { db.getCollectionNames().map(function(name) { return {"name":name, "size": db.getCollection(name).stats()["size"] || 0}; }).sort(function(a, b) { return b["size"] - a["size"]; }).forEach(function(x) { // MongoDB JavaScript Engine does not support string.padEnd let pad = " "; print(x.name + pad.slice(0, Math.max(16 - x.name.length, 0)) + ":\t" + x.size); }); } getCollectionSizes();Результат
values201 : 28512035211 objectValues201 : 25813237601 message201 : 23044451628 logg201 : 13106602059 fs.chunks : 9846541595 odataOpuConsumptionReading: 1288808159 values : 1052508175 odataByHoursZones2: 791091960 opuReadings : 470658787 opuConsumptionHour: 461311843