{"record":{"id":"61a0e89ebf529df0","repo":"mongodb/node-mongodb-native","slug":"invalid-server-api-version-versiontovalidate-m","errorCode":null,"errorMessage":"Invalid server API version=${versionToValidate}; must be in the following enum: [\"${Object.values(ServerApiVersion).join('\", \"')}\"]","messagePattern":"Invalid server API version=(.+?); must be in the following enum: \\[\"(.+?)\"\\]","errorType":"exception","errorClass":"MongoParseError","httpStatus":null,"severity":"error","filePath":"src/connection_string.ts","lineNumber":765,"sourceCode":"  },\n  bsonRegExp: {\n    type: 'boolean'\n  },\n  serverApi: {\n    target: 'serverApi',\n    transform({ values: [version] }): ServerApi {\n      const serverApiToValidate =\n        typeof version === 'string' ? ({ version } as ServerApi) : (version as ServerApi);\n      const versionToValidate = serverApiToValidate && serverApiToValidate.version;\n      if (!versionToValidate) {\n        throw new MongoParseError(\n          `Invalid \\`serverApi\\` property; must specify a version from the following enum: [\"${Object.values(\n            ServerApiVersion\n          ).join('\", \"')}\"]`\n        );\n      }\n      if (!Object.values(ServerApiVersion).some(v => v === versionToValidate)) {\n        throw new MongoParseError(\n          `Invalid server API version=${versionToValidate}; must be in the following enum: [\"${Object.values(\n            ServerApiVersion\n          ).join('\", \"')}\"]`\n        );\n      }\n      return serverApiToValidate;\n    }\n  },\n  checkKeys: {\n    type: 'boolean'\n  },\n  compressors: {\n    default: 'none',\n    target: 'compressors',\n    transform({ values }) {\n      const compressionList = new Set();\n      for (const compVal of values as (CompressorName[] | string)[]) {\n        const compValArray = typeof compVal === 'string' ? compVal.split(',') : compVal;","sourceCodeStart":747,"sourceCodeEnd":783,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/dce7939f86fb283e167ad709955abedb7bf23124/src/connection_string.ts#L747-L783","documentation":"Thrown by MongoParseError at src/connection_string.ts:765 in the `serverApi` transform when `version` is present but is not one of the `ServerApiVersion` enum values (currently only `'1'`). Distinct from error 198 which fires when version is missing entirely; this one fires when version is the wrong value. The message echoes the bad version and lists valid values.","triggerScenarios":"`{ serverApi: { version: '2' } }`, `{ serverApi: { version: 1 } }` (number not string '1'), `{ serverApi: { version: 'v1' } }`, or `{ serverApi: { version: 'stable' } }`.","commonSituations":"Assuming a numeric `1` works (must be the string `'1'`); using `'v1'` because of the enum key name; guessing `'stable'` because of Atlas API terminology.","solutions":["Use `version: ServerApiVersion.v1` (i.e. the string '1') — the only currently supported server API version.","Import `ServerApiVersion` from 'mongodb' to avoid hard-coding the wrong literal.","If you need a different API version, check the driver release notes — newer ServerApiVersions are added only when the server ships them."],"exampleFix":"// before\nnew MongoClient(uri, { serverApi: { version: 'v1' } })\n\n// after\nimport { ServerApiVersion } from 'mongodb'\nnew MongoClient(uri, { serverApi: { version: ServerApiVersion.v1 } })","handlingStrategy":"validation","validationCode":"import { ServerApiVersion } from 'mongodb';\nfunction assertServerApiVersionValid(serverApi) { const v = typeof serverApi === 'string' ? serverApi : serverApi?.version; if (v != null && !Object.values(ServerApiVersion).includes(v)) throw new Error(`serverApi.version must be one of ${Object.values(ServerApiVersion).join(', ')}`); }","typeGuard":"import { ServerApiVersion } from 'mongodb';\nfunction isServerApiVersion(v): v is ServerApiVersion { return Object.values(ServerApiVersion).some(valid => valid === v); }","tryCatchPattern":"try { new MongoClient(uri, { serverApi }); } catch (e) { if (e instanceof MongoParseError && /Invalid server API version/.test(e.message)) { serverApi = { ...serverApi, version: ServerApiVersion.v1 }; } else throw e; }","preventionTips":["Import `ServerApiVersion` from 'mongodb' and reference `ServerApiVersion.v1` instead of typing the literal.","Treat the value as an enum, not a free-form version string."],"tags":["connection-string","server-api","options","configuration"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}