From 92f1f189a81207352b3962de5a098bfe91249415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Fri, 14 Jun 2024 20:23:50 -0400 Subject: [PATCH] fix mongo stats --- src/database/mongo.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/database/mongo.js b/src/database/mongo.js index 131916cb6f..3a9be4e3a7 100644 --- a/src/database/mongo.js +++ b/src/database/mongo.js @@ -137,11 +137,11 @@ mongoModule.info = async function (db) { listCollections = listCollections.map(collectionInfo => ({ name: collectionInfo.ns, count: collectionInfo.count, - size: collectionInfo.size, - avgObjSize: collectionInfo.avgObjSize, - storageSize: collectionInfo.storageSize, - totalIndexSize: collectionInfo.totalIndexSize, - indexSizes: collectionInfo.indexSizes, + size: collectionInfo.storageStats && collectionInfo.storageStats.size, + avgObjSize: collectionInfo.storageStats && collectionInfo.storageStats.avgObjSize, + storageSize: collectionInfo.storageStats && collectionInfo.storageStats.storageSize, + totalIndexSize: collectionInfo.storageStats && collectionInfo.storageStats.totalIndexSize, + indexSizes: collectionInfo.storageStats && collectionInfo.storageStats.indexSizes, })); stats.mem = serverStatus.mem || { resident: 0, virtual: 0 }; @@ -169,11 +169,14 @@ mongoModule.info = async function (db) { async function getCollectionStats(db) { const items = await db.listCollections().toArray(); - return await Promise.all( - items.map(collection => db.collection(collection.name).aggregate([ - { $collStats: { latencyStats: {}, storageStats: {}, count: {} } }, - ])) + const cols = await Promise.all( + items.map( + collection => db.collection(collection.name).aggregate([ + { $collStats: { latencyStats: {}, storageStats: {}, count: {} } }, + ]).toArray() + ) ); + return cols.map(col => col[0]); } mongoModule.close = async function () {