{"id":"f4ef794564d9f800","repo":"mongodb/node-mongodb-native","slug":"option-family-must-be-4-or-6-got-transformvalu","errorCode":null,"errorMessage":"Option 'family' must be 4 or 6 got ${transformValue}.","messagePattern":"Option 'family' must be 4 or 6 got (.+?)\\.","errorType":"exception","errorClass":"MongoParseError","httpStatus":null,"severity":"error","filePath":"src/connection_string.ts","lineNumber":826,"sourceCode":"  dbName: {\n    type: 'string'\n  },\n  directConnection: {\n    default: false,\n    type: 'boolean'\n  },\n  driverInfo: {\n    default: {},\n    type: 'record'\n  },\n  enableUtf8Validation: { type: 'boolean', default: true },\n  family: {\n    transform({ name, values: [value] }): 4 | 6 {\n      const transformValue = getIntFromOptions(name, value);\n      if (transformValue === 4 || transformValue === 6) {\n        return transformValue;\n      }\n      throw new MongoParseError(`Option 'family' must be 4 or 6 got ${transformValue}.`);\n    }\n  },\n  fieldsAsRaw: {\n    type: 'record'\n  },\n  forceServerObjectId: {\n    default: false,\n    type: 'boolean'\n  },\n  fsync: {\n    deprecated: 'Please use journal instead',\n    target: 'writeConcern',\n    transform({ name, options, values: [value] }): WriteConcern {\n      const wc = WriteConcern.fromOptions({\n        writeConcern: {\n          ...options.writeConcern,\n          fsync: getBoolean(name, value)\n        }","sourceCodeStart":808,"sourceCodeEnd":844,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/connection_string.ts#L808-L844","documentation":"The `family` option restricts the IP stack to IPv4 or IPv6 and must be exactly `4` or `6`. The transform (src/connection_string.ts:820-827) parses the value to an integer and rejects anything other than 4 or 6.","triggerScenarios":"`{ family: 5 }`; `{ family: 0 }`; `{ family: '4.5' }` (parses to 4 only if parseInt, but a non-integer string may fail earlier in getIntFromOptions); `{ family: 10 }`.","commonSituations":"Misunderstanding family as a count or boolean; assuming 0 means 'both'; porting Node `net` family semantics with a wrong value.","solutions":["Set `family: 4` for IPv4-only or `family: 6` for IPv6-only","Omit the option to allow both stacks (autoSelectFamily handles dual-stack selection)"],"exampleFix":"// before\nnew MongoClient(uri, { family: 0 });\n// after\nnew MongoClient(uri, { family: 6 }); // IPv6 only","handlingStrategy":"validation","validationCode":"function isValidFamily(v) {\n  const n = Number(v);\n  return n === 4 || n === 6;\n}\nif (options.family != null && !isValidFamily(options.family)) {\n  throw new TypeError('family must be 4 or 6');\n}","typeGuard":"function isFamily(v) {\n  return v === 4 || v === 6;\n}","tryCatchPattern":null,"preventionTips":["Use exactly 4 (IPv4) or 6 (IPv6)","Omit the option to allow both stacks","Do not use 0 to mean 'both'"],"tags":["configuration","networking","options"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}