@egodigital/egoose
Version:
Helper classes and functions for Node.js 10 or later.
55 lines • 2.04 kB
JavaScript
;
/**
* This file is part of the @egodigital/egoose distribution.
* Copyright (c) e.GO Digital GmbH, Aachen, Germany (https://www.e-go-digital.com/)
*
* @egodigital/egoose is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, version 3.
*
* @egodigital/egoose is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.MongoDatabaseStatisticProviderBase = void 0;
const statistics_1 = require("../statistics");
/**
* A basic statistic provider that loads data from Mongo database.
*/
class MongoDatabaseStatisticProviderBase extends statistics_1.StatisticProviderBase {
/**
* Initializes a new instance of that class.
*
* @param {TDatabase} database The underlying database connection.
*/
constructor(database) {
super();
this.database = database;
}
/** @inheritdoc */
async close() {
await this.database
.disconnect();
}
/**
* Counts all documents of a collection.
*
* @param {Function} modelSelector The function that returns the model to use.
* @param {any} [filter] The optional filter.
*
* @return {Promise<number>} The promise that contains the number of documents.
*/
async countDocuments(modelSelector, filter) {
return await modelSelector(this.database)
.find(filter)
.countDocuments()
.exec();
}
}
exports.MongoDatabaseStatisticProviderBase = MongoDatabaseStatisticProviderBase;
//# sourceMappingURL=statistics.js.map