{"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/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/connection_string.ts#L883-L919","documentation":"`maxConnecting` caps how many connections the pool opens concurrently and must be a positive integer. The transform (src/connection_string.ts:896-904) parses it as an unsigned int; if the result is `0` it throws a MongoInvalidArgumentError, because zero would block all connection establishment.","triggerScenarios":"`{ maxConnecting: 0 }`; `{ maxConnecting: '0' }`; a config template that defaults to 0.","commonSituations":"Setting it to 0 intending 'unlimited' (omit the option instead); environment config templating producing 0.","solutions":["Set maxConnecting to a positive integer (default is 2)","Omit the option to use the default of 2","Do not use 0 to mean unlimited"],"exampleFix":"// before\nnew MongoClient(uri, { maxConnecting: 0 });\n// after\nnew MongoClient(uri, { maxConnecting: 4 });","handlingStrategy":"validation","validationCode":"if (options.maxConnecting != null && !(Number(options.maxConnecting) > 0)) {\n  throw new TypeError('maxConnecting must be a positive integer');\n}","typeGuard":"function isValidMaxConnecting(v) {\n  return Number.isInteger(Number(v)) && Number(v) > 0;\n}","tryCatchPattern":null,"preventionTips":["Use a positive integer for maxConnecting","Omit the option to use the default of 2","Never use 0 to mean unlimited"],"tags":["connection-pool","configuration","options"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}