{"record":{"id":"f54e24b923cccbbb","repo":"mongodb/node-mongodb-native","slug":"authmechanism-one-of-mechanisms-got-value","errorCode":null,"errorMessage":"authMechanism one of ${mechanisms}, got ${value}","messagePattern":"authMechanism one of (.+?), got (.+?)","errorType":"exception","errorClass":"MongoParseError","httpStatus":null,"severity":"error","filePath":"src/connection_string.ts","lineNumber":677,"sourceCode":"    transform({ name, options, values: [value] }): MongoCredentials {\n      if (!isRecord(value, ['username', 'password'] as const)) {\n        throw new MongoParseError(\n          `${name} must be an object with 'username' and 'password' properties`\n        );\n      }\n      return MongoCredentials.merge(options.credentials, {\n        username: value.username,\n        password: value.password\n      });\n    }\n  },\n  authMechanism: {\n    target: 'credentials',\n    transform({ options, values: [value] }): MongoCredentials {\n      const mechanisms = Object.values(AuthMechanism);\n      const [mechanism] = mechanisms.filter(m => m.match(RegExp(String.raw`\\b${value}\\b`, 'i')));\n      if (!mechanism) {\n        throw new MongoParseError(`authMechanism one of ${mechanisms}, got ${value}`);\n      }\n      let source = options.credentials?.source;\n      if (\n        mechanism === AuthMechanism.MONGODB_PLAIN ||\n        AUTH_MECHS_AUTH_SRC_EXTERNAL.has(mechanism)\n      ) {\n        // some mechanisms have '$external' as the Auth Source\n        source = '$external';\n      }\n\n      let password = options.credentials?.password;\n      if (mechanism === AuthMechanism.MONGODB_X509 && password === '') {\n        password = undefined;\n      }\n      return MongoCredentials.merge(options.credentials, {\n        mechanism,\n        source,\n        password","sourceCodeStart":659,"sourceCodeEnd":695,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/dce7939f86fb283e167ad709955abedb7bf23124/src/connection_string.ts#L659-L695","documentation":"Thrown by MongoParseError at src/connection_string.ts:677 in the `authMechanism` transform when the supplied value does not match (case-insensitive whole-word) any entry of the `AuthMechanism` enum: MONGODB-AWS, DEFAULT, GSSAPI, PLAIN, SCRAM-SHA-1, SCRAM-SHA-256, MONGODB-X509, MONGODB-OIDC. The error message lists the accepted values and echoes the bad value.","triggerScenarios":"`?authMechanism=SCRAM-SHA256` (missing hyphen), `?authMechanism=aws`, `?authMechanism=LDAP`, or `{ authMechanism: 'mongo-db-x509' }`.","commonSituations":"Misspelling SCRAM-SHA-256 as SCRAM-SHA256; using 'aws' instead of 'MONGODB-AWS'; copying examples from older docs that name mechanisms differently; case/formatting typos.","solutions":["Use one of the exact enum values: MONGODB-AWS, DEFAULT, GSSAPI, PLAIN, SCRAM-SHA-1, SCRAM-SHA-256, MONGODB-X509, MONGODB-OIDC (case-insensitive).","If using the options object, import the AuthMechanism enum and reference it: `authMechanism: AuthMechanism.MONGODB_X509`.","Re-read the error message — it lists every valid value."],"exampleFix":"// before\nnew MongoClient('mongodb://host/?authMechanism=SCRAM-SHA256')\n\n// after\nnew MongoClient('mongodb://host/?authMechanism=SCRAM-SHA-256')","handlingStrategy":"validation","validationCode":"const VALID = new Set(['MONGODB-AWS','DEFAULT','GSSAPI','PLAIN','SCRAM-SHA-1','SCRAM-SHA-256','MONGODB-X509','MONGODB-OIDC']);\nfunction assertValidMechanism(value) { if (!VALID.has(String(value).toUpperCase())) throw new Error(`authMechanism must be one of ${[...VALID].join(', ')}`); }","typeGuard":"import { AuthMechanism } from 'mongodb';\nfunction isAuthMechanism(v): v is AuthMechanism { return Object.values(AuthMechanism).some(m => new RegExp(`\\\\b${v}\\\\b`, 'i').test(m)); }","tryCatchPattern":"try { new MongoClient(uri, options); } catch (e) { if (e instanceof MongoParseError && /authMechanism one of/.test(e.message)) { options.authMechanism = 'SCRAM-SHA-256'; } else throw e; }","preventionTips":["Import the AuthMechanism enum from 'mongodb' and reference its members rather than typing strings.","Cross-check spelling against the error message, which enumerates every valid value."],"tags":["connection-string","authentication","options","configuration"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}