Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions src/integrations/database/implementations/mongodb/MongoDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,21 @@ export default class MongoDB implements Driver
this.#databaseName = databaseName;
}

get connected()
{
return this.#connected;
}
get connected() { return this.#connected; }

async connect(): Promise<void>
{
try
{
this.#client = await this.#createClient(this.#connectionString);

this.#client.on('open', () => { this.#connected = true; });
this.#client.on('close', () => { this.#connected = false; });

this.#client.on('serverHeartbeatSucceeded', () => { this.#connected = true; });
this.#client.on('serverHeartbeatFailed', () => { this.#connected = false; });

this.#database = this.#getDatabase(this.#databaseName);

this.#connected = true;
}
catch (error: unknown)
{
Expand Down Expand Up @@ -269,16 +266,7 @@ export default class MongoDB implements Driver

async #createClient(connectionString: string): Promise<MongoClient>
{
try
{
return await MongoClient.connect(connectionString);
}
catch (error: unknown)
{
const message = error instanceof Error ? error.message : undefined;

throw new NotConnected(message);
}
return MongoClient.connect(connectionString);
}

#buildRecordData(data: Document, fields?: RecordField[]): RecordData
Expand Down
Loading