fixed reading DB with mongo views #476

This commit is contained in:
Jan Prochazka 2023-02-03 09:59:53 +01:00
parent dc6eff7f9e
commit 8fe6cb1f71

View File

@ -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;