{"record":{"id":"f6b41a74f387dad9","repo":"mongodb/node-mongodb-native","slug":"name-must-be-either-true-or-false","errorCode":null,"errorMessage":"${name} must be either \"true\" or \"false\"","messagePattern":"(.+?) must be either \"true\" or \"false\"","errorType":"exception","errorClass":"MongoParseError","httpStatus":null,"severity":"error","filePath":"src/connection_string.ts","lineNumber":184,"sourceCode":"function checkTLSOptions(allOptions: CaseInsensitiveMap): void {\n  if (!allOptions) return;\n  const check = (a: string, b: string) => {\n    if (allOptions.has(a) && allOptions.has(b)) {\n      throw new MongoAPIError(`The '${a}' option cannot be used with the '${b}' option`);\n    }\n  };\n  check('tlsInsecure', 'tlsAllowInvalidCertificates');\n  check('tlsInsecure', 'tlsAllowInvalidHostnames');\n}\nfunction getBoolean(name: string, value: unknown): boolean {\n  if (typeof value === 'boolean') return value;\n  switch (value) {\n    case 'true':\n      return true;\n    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}","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/dce7939f86fb283e167ad709955abedb7bf23124/src/connection_string.ts#L166-L202","documentation":"Boolean URI options (tls, ssl, loadBalanced, directConnection, retryWrites, etc.) only accept the literal strings 'true' or 'false', or a real boolean when passed via the options object. getBoolean throws for anything else to avoid silent coercion surprises.","triggerScenarios":"Passing a URI query value like 'tls=yes', 'ssl=1', 'loadBalanced=TRUE' (uppercase), or 'retryWrites=0' to a boolean option. Also triggered by a boolean option set via the options object with a non-boolean, non-'true'/'false' string.","commonSituations":"Coming from another driver that accepts '1'/'0' or 'yes'/'no', copy-pasting config from a YAML/ENV that uses different truthiness, or case-sensitivity assumptions.","solutions":["Use the lowercase literal 'true' or 'false' in the URI.","If passing via options object, pass an actual boolean (true/false), not a string."],"exampleFix":"// before\nnew MongoClient('mongodb://h/db?tls=true&retryWrites=1');\n// after\nnew MongoClient('mongodb://h/db?tls=true&retryWrites=true');","handlingStrategy":"validation","validationCode":"const BOOL_RE = /^(true|false)$/i;\nfunction assertBoolOption(name: string, value: unknown) {\n  if (typeof value === 'boolean') return;\n  if (typeof value === 'string' && BOOL_RE.test(value)) return;\n  throw new Error(`${name} must be 'true' or 'false', got: ${value}`);\n}","typeGuard":"function isBoolOptionValue(v: unknown): v is boolean | 'true' | 'false' {\n  return typeof v === 'boolean' || (typeof v === 'string' && /^(true|false)$/i.test(v));\n}","tryCatchPattern":null,"preventionTips":["Pass booleans (true/false) from the options object rather than strings.","Do not reuse config from drivers with different truthiness conventions."],"tags":["connection-string","validation","boolean","parsing"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}