{"record":{"id":"ba1825c4cd65b44d","repo":"mongodb/node-mongodb-native","slug":"name-must-be-an-object","errorCode":null,"errorMessage":"${name} must be an object","messagePattern":"(.+?) must be an object","errorType":"exception","errorClass":"MongoParseError","httpStatus":null,"severity":"error","filePath":"src/connection_string.ts","lineNumber":617,"sourceCode":"      break;\n    case 'int':\n      mongoOptions[name] = getIntFromOptions(name, values[0]);\n      break;\n    case 'uint':\n      mongoOptions[name] = getUIntFromOptions(name, values[0]);\n      break;\n    case 'string':\n      if (values[0] == null) {\n        break;\n      }\n      // The value should always be a string here, but since the array is typed as unknown\n      // there still needs to be an explicit cast.\n      // eslint-disable-next-line @typescript-eslint/no-base-to-string\n      mongoOptions[name] = String(values[0]);\n      break;\n    case 'record':\n      if (!isRecord(values[0])) {\n        throw new MongoParseError(`${name} must be an object`);\n      }\n      mongoOptions[name] = values[0];\n      break;\n    case 'any':\n      mongoOptions[name] = values[0];\n      break;\n    default: {\n      if (!transform) {\n        throw new MongoParseError('Descriptors missing a type must define a transform');\n      }\n      const transformValue = transform({ name, options: mongoOptions, values });\n      mongoOptions[name] = transformValue;\n      break;\n    }\n  }\n}\n\ninterface OptionDescriptor {","sourceCodeStart":599,"sourceCodeEnd":635,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/dce7939f86fb283e167ad709955abedb7bf23124/src/connection_string.ts#L599-L635","documentation":"Thrown by MongoParseError at src/connection_string.ts:617 inside `setOption`'s `record` case when the supplied value fails `isRecord()`. Any option typed as `record` (e.g. `autoEncryption`) must be a plain object; passing a string, number, array, or null is rejected. `${name}` is the resolved option name.","triggerScenarios":"Passing `autoEncryption: 'required'` instead of an object; passing `autoEncryption: null`; double-encoding JSON (passing a stringified object).","commonSituations":"Loading options from a JSON or YAML file and accidentally leaving the value as a string; toggling a feature flag where the type changed between driver versions.","solutions":["Pass the option as a plain object literal matching the expected schema (e.g. AutoEncryptionOptions).","If the value comes from JSON, parse it before passing it: `JSON.parse(value)`.","Check the option name in the error message (`${name}`) to identify which field is malformed."],"exampleFix":"// before\nnew MongoClient(uri, { autoEncryption: '{ keyVaultNamespace: \"encryption.__keyVault\" }' })\n\n// after\nnew MongoClient(uri, { autoEncryption: { keyVaultNamespace: 'encryption.__keyVault', kmsProviders: { aws: {} } } })","handlingStrategy":"type-guard","validationCode":"function isPlainObject(v) { return typeof v === 'object' && v !== null && !Array.isArray(v); }\nfunction assertRecordOptions(options) {\n  for (const [k, v] of Object.entries(options)) if (!isPlainObject(v) && /autoEncryption|readConcern|writeConcern/.test(k)) throw new Error(`${k} must be an object.`);\n}","typeGuard":"function isRecord(v, requiredKeys = []) { if (typeof v !== 'object' || v === null || Array.isArray(v)) return false; return requiredKeys.every(k => k in v); }","tryCatchPattern":"try { new MongoClient(uri, options); } catch (e) { if (e instanceof MongoParseError && /must be an object$/.test(e.message)) { /* coerce or remove the offending option */ } else throw e; }","preventionTips":["Type the options object against the driver's published TypeScript types so the compiler catches non-object values.","If loading options from JSON/YAML, parse and validate the schema before passing them in."],"tags":["connection-string","options","configuration","type-validation"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}