{"record":{"id":"2217379d9eff4670","repo":"mongodb/node-mongodb-native","slug":"name-can-only-be-a-positive-int-value-got-v","errorCode":null,"errorMessage":"${name} can only be a positive int value, got: ${value}","messagePattern":"(.+?) can only be a positive int value, got: (.+?)","errorType":"exception","errorClass":"MongoParseError","httpStatus":null,"severity":"error","filePath":"src/connection_string.ts","lineNumber":199,"sourceCode":"    case 'false':\n      return false;\n    default:\n      throw new MongoParseError(`${name} must be either \"true\" or \"false\"`);\n  }\n}\n\nfunction getIntFromOptions(name: string, value: unknown): number {\n  const parsedInt = parseInteger(value);\n  if (parsedInt != null) {\n    return parsedInt;\n  }\n  throw new MongoParseError(`Expected ${name} to be stringified int value, got: ${value}`);\n}\n\nfunction getUIntFromOptions(name: string, value: unknown): number {\n  const parsedValue = getIntFromOptions(name, value);\n  if (parsedValue < 0) {\n    throw new MongoParseError(`${name} can only be a positive int value, got: ${value}`);\n  }\n  return parsedValue;\n}\n\nfunction* entriesFromString(value: string): Generator<[string, string]> {\n  if (value === '') {\n    return;\n  }\n  const keyValuePairs = value.split(',');\n  for (const keyValue of keyValuePairs) {\n    const [key, value] = keyValue.split(/:(.*)/);\n    if (value == null) {\n      throw new MongoParseError('Cannot have undefined values in key value pairs');\n    }\n\n    yield [key, value];\n  }\n}","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/dce7939f86fb283e167ad709955abedb7bf23124/src/connection_string.ts#L181-L217","documentation":"Unsigned-int options (srvMaxHosts and similar) accept any integer but reject negatives. getUIntFromOptions calls getIntFromOptions then checks for <0 and throws, including the original value in the message.","triggerScenarios":"Passing a negative integer to an unsigned option, e.g. 'srvMaxHosts=-1' in the URI or srvMaxHosts: -1 in options.","commonSituations":"Using -1 as a 'disable' sentinel the way some other libraries do, or arithmetic that underflows.","solutions":["Use 0 (or omit the option) to disable srvMaxHosts.","Pass a positive integer to cap the number of hosts."],"exampleFix":"// before\nnew MongoClient('mongodb+srv://h/db?srvMaxHosts=-1');\n// after\nnew MongoClient('mongodb+srv://h/db?srvMaxHosts=0');","handlingStrategy":"validation","validationCode":"function assertUIntOption(name: string, value: unknown) {\n  assertIntOption(name, value);\n  if (Number(value) < 0) throw new Error(`${name} must be >= 0, got: ${value}`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use 0 as the 'disable' sentinel for unsigned options, never -1.","Validate numeric config at the boundary where it enters your app."],"tags":["connection-string","validation","integer"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}