{"id":"81122c04512beb96","repo":"mongodb/node-mongodb-native","slug":"authmechanismproperties-must-be-an-object","errorCode":null,"errorMessage":"AuthMechanismProperties must be an object","messagePattern":"AuthMechanismProperties must be an object","errorType":"exception","errorClass":"MongoParseError","httpStatus":null,"severity":"error","filePath":"src/connection_string.ts","lineNumber":721,"sourceCode":"    target: 'credentials',\n    transform({ options, values }): MongoCredentials {\n      // We can have a combination of options passed in the URI and options passed\n      // as an object to the MongoClient. So we must transform the string options\n      // as well as merge them together with a potentially provided object.\n      let mechanismProperties = Object.create(null);\n\n      for (const optionValue of values) {\n        if (typeof optionValue === 'string') {\n          for (const [key, value] of entriesFromString(optionValue)) {\n            try {\n              mechanismProperties[key] = getBoolean(key, value);\n            } catch {\n              mechanismProperties[key] = value;\n            }\n          }\n        } else {\n          if (!isRecord(optionValue)) {\n            throw new MongoParseError('AuthMechanismProperties must be an object');\n          }\n          mechanismProperties = { ...optionValue };\n        }\n      }\n      return MongoCredentials.merge(options.credentials, {\n        mechanismProperties\n      });\n    }\n  },\n  authSource: {\n    target: 'credentials',\n    transform({ options, values: [value] }): MongoCredentials {\n      const source = String(value);\n      return MongoCredentials.merge(options.credentials, { source });\n    }\n  },\n  autoEncryption: {\n    type: 'record'","sourceCodeStart":703,"sourceCodeEnd":739,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/connection_string.ts#L703-L739","documentation":"`authMechanismProperties` accepts either a connection-string-style string (e.g. 'SERVICE_NAME:svc,CANONICALIZE_HOST_NAME:true') or a plain object. The transform (src/connection_string.ts:702-729) iterates values; any value that is neither a string nor a plain object (record) triggers this MongoParseError.","triggerScenarios":"`{ authMechanismProperties: 123 }`; `{ authMechanismProperties: true }`; `{ authMechanismProperties: ['SERVICE_NAME:x'] }` (array is not an object); `{ authMechanismProperties: null }`.","commonSituations":"Loosely-typed config producing a number/boolean; JSON config parsed to an unexpected type; passing an array instead of an object.","solutions":["Pass authMechanismProperties as an object: { SERVICE_NAME: 'kerberos', CANONICALIZE_HOST_NAME: true }","Or as a comma-delimited string: 'SERVICE_NAME:kerberos,CANONICALIZE_HOST_NAME:true'","For OIDC TOKEN_RESOURCE values containing commas, pass as an object (cannot be expressed in the URI)"],"exampleFix":"// before\nnew MongoClient(uri, { authMechanismProperties: 123 });\n// after\nnew MongoClient(uri, {\n  authMechanismProperties: { SERVICE_NAME: 'mongod', CANONICALIZE_HOST_NAME: true }\n});","handlingStrategy":"type-guard","validationCode":"function isValidMechProperties(v) {\n  return typeof v === 'string' || (v != null && typeof v === 'object' && !Array.isArray(v));\n}\nif (options.authMechanismProperties && !isValidMechProperties(options.authMechanismProperties)) {\n  throw new TypeError('authMechanismProperties must be a string or object');\n}","typeGuard":"function isAuthMechanismProperties(v) {\n  return typeof v === 'string' || (v != null && typeof v === 'object' && !Array.isArray(v));\n}","tryCatchPattern":null,"preventionTips":["Pass authMechanismProperties as an object in TypeScript code","Avoid numbers/booleans from loosely-typed config sources","For OIDC TOKEN_RESOURCE with commas, always use the object form"],"tags":["authentication","configuration","kerberos","oidc"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}