From b80cbea1bcb535411437d328029f3dd6a7d8ccd2 Mon Sep 17 00:00:00 2001 From: "SPRINX0\\prochazka" Date: Fri, 21 Nov 2025 16:07:27 +0100 Subject: [PATCH] show mongo collection sizes #552 --- .../src/backend/Analyser.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/plugins/dbgate-plugin-mongo/src/backend/Analyser.js b/plugins/dbgate-plugin-mongo/src/backend/Analyser.js index 3d3c6e598..f8001334a 100644 --- a/plugins/dbgate-plugin-mongo/src/backend/Analyser.js +++ b/plugins/dbgate-plugin-mongo/src/backend/Analyser.js @@ -16,12 +16,16 @@ class Analyser extends DatabaseAnalyser { collections .filter((x) => x.type == 'collection') .map((x) => - this.dbhan - .getDatabase() - .collection(x.name) - .aggregate([{ $collStats: { count: {} } }]) - .toArray() - .then((resp) => ({ name: x.name, count: resp[0].count })) + this.dbhan + .getDatabase() + .collection(x.name) + .aggregate([{ $collStats: { count: {}, storageStats: {} } }]) + .toArray() + .then((resp) => ({ + name: x.name, + count: resp[0].count, + size: resp[0].storageStats?.size + })) ) ); } catch (e) { @@ -29,11 +33,13 @@ class Analyser extends DatabaseAnalyser { stats = {}; } + const res = this.mergeAnalyseResult({ collections: [ ...collections.map((x, index) => ({ pureName: x.name, tableRowCount: stats[index]?.count, + sizeBytes: stats[index]?.size, uniqueKey: [{ columnName: '_id' }], partitionKey: [{ columnName: '_id' }], clusterKey: [{ columnName: '_id' }],