MCPcopy Create free account
hub / github.com/mikro-orm/mikro-orm / createClient

Method createClient

packages/mongodb/src/MongoConnection.ts:76–103  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

74 }
75
76 createClient(): void {
77 let driverOptions = this.options.driverOptions ?? this.config.get('driverOptions');
78
79 if (typeof driverOptions === 'function') {
80 driverOptions = driverOptions();
81 }
82
83 if (driverOptions instanceof MongoClient) {
84 this.logger.log('info', 'Reusing MongoClient provided via `driverOptions`');
85 this.#client = driverOptions;
86 } else {
87 this.#client = new MongoClient(
88 this.config.get('clientUrl'),
89 this.mapOptions(driverOptions as MongoClientOptions),
90 );
91 this.#client.appendMetadata({
92 name: 'MikroORM',
93 version: Utils.getORMVersion(),
94 });
95 const onCreateConnection = this.options.onCreateConnection ?? this.config.get('onCreateConnection');
96 /* v8 ignore next */
97 this.#client.on('connectionCreated', () => {
98 void onCreateConnection?.(this.#client);
99 });
100 }
101
102 this.#db = this.#client.db(this.config.get('dbName'));
103 }
104
105 override async close(force?: boolean): Promise<void> {
106 await this.#client?.close(force);

Callers 1

getClientMethod · 0.95

Calls 5

mapOptionsMethod · 0.95
getORMVersionMethod · 0.80
onMethod · 0.80
getMethod · 0.65
logMethod · 0.65

Tested by

no test coverage detected