{"record":{"id":"0829482eef8529b0","repo":"mongodb/node-mongodb-native","slug":"maxconnecting-must-be-0-if-specified","errorCode":null,"errorMessage":"maxConnecting must be > 0 if specified","messagePattern":"maxConnecting must be > 0 if specified","errorType":"exception","errorClass":"MongoInvalidArgumentError","httpStatus":null,"severity":"error","filePath":"src/connection_string.ts","lineNumber":901,"sourceCode":"  },\n  loadBalanced: {\n    default: false,\n    type: 'boolean'\n  },\n  localThresholdMS: {\n    default: 15,\n    type: 'uint'\n  },\n  maxAdaptiveRetries: {\n    default: 2,\n    type: 'uint'\n  },\n  maxConnecting: {\n    default: 2,\n    transform({ name, values: [value] }): number {\n      const maxConnecting = getUIntFromOptions(name, value);\n      if (maxConnecting === 0) {\n        throw new MongoInvalidArgumentError('maxConnecting must be > 0 if specified');\n      }\n      return maxConnecting;\n    }\n  },\n  maxIdleTimeMS: {\n    default: 0,\n    type: 'uint'\n  },\n  maxPoolSize: {\n    default: 100,\n    type: 'uint'\n  },\n  maxStalenessSeconds: {\n    target: 'readPreference',\n    transform({ name, options, values: [value] }) {\n      const maxStalenessSeconds = getUIntFromOptions(name, value);\n      if (options.readPreference) {\n        return ReadPreference.fromOptions({","sourceCodeStart":883,"sourceCodeEnd":919,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/dce7939f86fb283e167ad709955abedb7bf23124/src/connection_string.ts#L883-L919","documentation":"`maxConnecting` caps how many connections the pool may set up concurrently per server (default 2). The transform at src/connection_string.ts:898 parses the value as an unsigned int via getUIntFromOptions, then at src/connection_string.ts:900 throws MongoInvalidArgumentError when the result is exactly 0. Other negative/non-int values fail earlier in getUIntFromOptions.","triggerScenarios":"Passing `maxConnecting: 0` (e.g. to mean 'no limit' or 'disabled'); reading the value from config where unset becomes 0 instead of undefined; copying the convention from `maxPoolSize` where 0 is treated as unlimited.","commonSituations":"Config templates that initialize all numeric pool options to 0; operators assuming 0 disables the cap; copying from maxPoolSize semantics.","solutions":["Omit `maxConnecting` to accept the default of 2.","Pass a positive integer such as `maxConnecting: 10`.","Fix config loading so an unset value stays `undefined` rather than becoming `0`."],"exampleFix":"// before\nnew MongoClient(uri, { maxConnecting: 0 });\n\n// after\nnew MongoClient(uri, { maxConnecting: 10 });","handlingStrategy":"validation","validationCode":"if (opts.maxConnecting !== undefined) {\n  const n = Number(opts.maxConnecting);\n  if (!Number.isInteger(n) || n <= 0) throw new Error('maxConnecting must be a positive integer');\n}","typeGuard":"function isPositiveInt(v: unknown): v is number { return typeof v === 'number' && Number.isInteger(v) && v > 0; }","tryCatchPattern":"try { client = new MongoClient(uri, opts); } catch (e) { if (e instanceof MongoInvalidArgumentError && /maxConnecting/.test(e.message)) { delete opts.maxConnecting; client = new MongoClient(uri, opts); } else throw e; }","preventionTips":["Do not initialize numeric pool options to 0 in config defaults.","Map 'unset' to `undefined`, not `0`.","Remember maxConnecting has no 'unlimited' value — omit it instead."],"tags":["connection-pool","configuration"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}