Skip to content

Commit

Permalink
feat(mongodb): add support for collection prefix in ErrsoleMongoDB
Browse files Browse the repository at this point in the history
  • Loading branch information
SaiKumar2121 committed Nov 25, 2024
1 parent de619c8 commit 850323b
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,31 @@ class ErrsoleMongoDB extends EventEmitter {
*/
constructor (uri, dbNameOrOptions, options = {}) {
super();

this.name = packageJSON.name;
this.version = packageJSON.version || '0.0.0';

const { collectionPrefix, ...connectionOptions } = typeof dbNameOrOptions === 'object' ? dbNameOrOptions : options;

this.uri = uri;
this.dbName = typeof dbNameOrOptions === 'string' ? dbNameOrOptions : undefined;
this.connectionOptions = typeof dbNameOrOptions === 'object' ? dbNameOrOptions : options;
this.connectionOptions = connectionOptions;

const prefix = collectionPrefix
? `${collectionPrefix.toLowerCase().replace(/[^a-z0-9]/g, '')}_`
: 'errsole_';

this.client = new MongoClient(this.uri, this.connectionOptions);
this.logsCollectionName = 'errsole_logs';
this.notificationsCollectionName = 'errsole_notifications';
this.usersCollectionName = 'errsole_users';
this.configCollectionName = 'errsole_config';
this.logsCollectionName = `${prefix}logs`;
this.notificationsCollectionName = `${prefix}notifications`;
this.usersCollectionName = `${prefix}users`;
this.configCollectionName = `${prefix}config`;

this.isConnectionInProgress = true;
this.pendingLogs = [];
this.batchSize = 100;
this.flushInterval = 1000;

this.init();
}

Expand Down

0 comments on commit 850323b

Please sign in to comment.