Fix global db var not init when checking the DB
MODIFY
src/start.ts
src/start.ts
@@ -82,8 +82,6 @@ export default class Bootstrap {
}
// Connect to the Database
await Bootstrap.database.start();
- // Keep a global reference
- global.database = Bootstrap.database;
// Log
await this.logDuration(startTimeMillis, 'Connected to the Database successfully');

MODIFY
src/storage/mongodb/MongoDBStorage.ts
src/storage/mongodb/MongoDBStorage.ts
import { ChangeStreamDocument, Collection, CreateIndexesOptions, Db, GridFSBucket, IndexSpecification, MongoClient, ReadPreferenceMode } from 'mongodb';
+import global, { DatabaseDocumentChange } from '../../types/GlobalType';
import mongoUriBuilder, { MongoUriConfig } from 'mongo-uri-builder';
import BackendError from '../../exception/BackendError';
import Configuration from '../../utils/Configuration';
import Constants from '../../utils/Constants';
-import { DatabaseDocumentChange } from '../../types/GlobalType';
import DatabaseUtils from './DatabaseUtils';
import { LockEntity } from '../../types/Locking';
import LockingManager from '../../locking/LockingManager';
@@ -277,6 +277,8 @@ export default class MongoDBStorage {
);
// Get the EVSE DB
this.database = mongoDBClient.db();
+ // Keep a global reference
+ global.database = this;
// Check Database only when migration is active
if (this.migrationConfig.active) {
await this.checkDatabase();

Fix global db var not init when checking the DB