import { MongoClient } from 'mongodb'
-import { Storage } from './Storage.js'
import { BaseError } from '../../exception/index.js'
import { type Statistics, StorageType } from '../../types/index.js'
import { Constants } from '../../utils/index.js'
+import { Storage } from './Storage.js'
export class MongoDBStorage extends Storage {
private readonly client?: MongoClient
public async storePerformanceStatistics (performanceStatistics: Statistics): Promise<void> {
try {
+ this.setPerformanceStatistics(performanceStatistics)
this.checkDBConnection()
await this.client
?.db(this.dbName)
.collection<Statistics>(Constants.PERFORMANCE_RECORDS_TABLE)
- .replaceOne({ id: performanceStatistics.id }, performanceStatistics, { upsert: true })
+ .replaceOne({ id: performanceStatistics.id }, performanceStatistics, {
+ upsert: true
+ })
} catch (error) {
this.handleDBError(StorageType.MONGO_DB, error as Error, Constants.PERFORMANCE_RECORDS_TABLE)
}
}
public async close (): Promise<void> {
+ this.clearPerformanceStatistics()
try {
if (this.connected && this.client != null) {
await this.client.close()