From 8fe6cb1f711587b90bf4973b4fe14b487e0b64cb Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Fri, 3 Feb 2023 09:59:53 +0100 Subject: [PATCH] fixed reading DB with mongo views #476 --- .../src/backend/Analyser.js | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/plugins/dbgate-plugin-mongo/src/backend/Analyser.js b/plugins/dbgate-plugin-mongo/src/backend/Analyser.js index a4df793f..9926c68d 100644 --- a/plugins/dbgate-plugin-mongo/src/backend/Analyser.js +++ b/plugins/dbgate-plugin-mongo/src/backend/Analyser.js @@ -6,15 +6,24 @@ class Analyser extends DatabaseAnalyser { } async _runAnalysis() { - const collections = await this.pool.__getDatabase().listCollections().toArray(); + const collectionsAndViews = await this.pool.__getDatabase().listCollections().toArray(); + const collections = collectionsAndViews.filter((x) => x.type == 'collection'); + const views = collectionsAndViews.filter((x) => x.type == 'view'); - const stats = await Promise.all(collections.map((x) => this.pool.__getDatabase().collection(x.name).stats())); + const stats = await Promise.all( + collections.filter((x) => x.type == 'collection').map((x) => this.pool.__getDatabase().collection(x.name).stats()) + ); const res = this.mergeAnalyseResult({ - collections: collections.map((x, index) => ({ - pureName: x.name, - tableRowCount: stats[index].count, - })), + collections: [ + ...collections.map((x, index) => ({ + pureName: x.name, + tableRowCount: stats[index].count, + })), + ...views.map((x, index) => ({ + pureName: x.name, + })), + ], }); // console.log('MERGED', res); return res;