MCPcopy
hub / github.com/mongodb/node-mongodb-native / newClient

Method newClient

test/tools/runner/config.ts:223–325  ·  view source on GitHub ↗
(
    urlOrQueryOptions?: string | Record<string, any>,
    serverOptions?: MongoClientOptions
  )

Source from the content-addressed store, hash-verified

221 }
222
223 newClient(
224 urlOrQueryOptions?: string | Record<string, any>,
225 serverOptions?: MongoClientOptions
226 ): MongoClient {
227 const baseOptions: MongoClientOptions = this.compressor
228 ? {
229 compressors: this.compressor
230 }
231 : {};
232
233 serverOptions = Object.assign(baseOptions, getEnvironmentalOptions(), serverOptions);
234
235 if (this.loggingEnabled && !Object.hasOwn(serverOptions, 'mongodbLogPath')) {
236 serverOptions = this.setupLogging(serverOptions);
237 }
238
239 // Support MongoClient constructor form (url, options) for `newClient`.
240 if (typeof urlOrQueryOptions === 'string') {
241 if ('host' in serverOptions || 'port' in serverOptions) {
242 throw new Error(`Cannot use options to specify host/port, must be in ${urlOrQueryOptions}`);
243 }
244
245 const newClient: MongoClient = new MongoClient(urlOrQueryOptions, serverOptions);
246 return newClient;
247 }
248
249 const queryOptions = urlOrQueryOptions ?? {};
250
251 // Fall back.
252 let dbHost = queryOptions.host || this.options.host;
253 if (dbHost.indexOf('.sock') !== -1) {
254 dbHost = qs.escape(dbHost);
255 }
256 delete queryOptions.host;
257 const dbPort = queryOptions.port || this.options.port;
258 delete queryOptions.port;
259
260 if (this.options.authMechanism && !serverOptions.authMechanism) {
261 Object.assign(queryOptions, {
262 authMechanism: this.options.authMechanism
263 });
264 }
265
266 if (this.options.authMechanismProperties && !serverOptions.authMechanismProperties) {
267 Object.assign(queryOptions, {
268 authMechanismProperties: convertToConnStringMap(this.options.authMechanismProperties)
269 });
270 }
271
272 if (this.options.replicaSet && !serverOptions.replicaSet) {
273 Object.assign(queryOptions, { replicaSet: this.options.replicaSet });
274 }
275
276 if (this.options.proxyURIParams) {
277 for (const [name, value] of Object.entries(this.options.proxyURIParams)) {
278 if (value) {
279 queryOptions[name] = value;
280 }

Callers 15

helloMethod · 0.95
runCmapTestSuiteFunction · 0.45
configureFailPointFunction · 0.45
clearFailPointFunction · 0.45
newClientMethod · 0.45
runUnifiedTestFunction · 0.45
beforeEachFilterFunction · 0.45
runTestSuiteTestFunction · 0.45
setupMethod · 0.45
objectid.test.tsFile · 0.45

Calls 3

setupLoggingMethod · 0.95
getEnvironmentalOptionsFunction · 0.90
convertToConnStringMapFunction · 0.85

Tested by 15

setupFunction · 0.36
cleanUpUsersFunction · 0.36
createUsersFunction · 0.36
testCappedFunction · 0.36
initMethod · 0.36
testFunction · 0.36
testFunction · 0.36
findSortFunction · 0.36
cursorSortFunction · 0.36
defineTestFunction · 0.36
makeClientFunction · 0.36
runProseTestsForFunction · 0.36