{"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/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/connection_string.ts#L747-L783","documentation":"`serverApi.version` must be one of the `ServerApiVersion` enum values (currently only the string '1'). A version was supplied but is not a recognized value, so the driver refuses to pin an unsupported Stable API version.","triggerScenarios":"`{ serverApi: '2' }`; `{ serverApi: { version: 'v1' } }` (must be '1', not 'v1'); `{ serverApi: { version: 1 } }` (number, not the string '1'); `{ serverApi: 'latest' }`.","commonSituations":"Guessing version strings; using 'v1' instead of '1'; passing a number; assuming 'latest' or a future version string works.","solutions":["Use the `ServerApiVersion.v1` constant (the string '1')","Import { ServerApiVersion } from 'mongodb' and reference the enum rather than hardcoding strings","Do not pass numbers — version must be a string"],"exampleFix":"// before\nnew MongoClient(uri, { serverApi: { version: 'v1' } });\n// after\nimport { ServerApiVersion } from 'mongodb';\nnew MongoClient(uri, { serverApi: { version: ServerApiVersion.v1 } });","handlingStrategy":"validation","validationCode":"import { ServerApiVersion } from 'mongodb';\nconst VALID = new Set(Object.values(ServerApiVersion));\nfunction isValidServerApiVersion(v) {\n  const version = typeof v === 'string' ? v : v?.version;\n  return VALID.has(version);\n}\nif (options.serverApi && !isValidServerApiVersion(options.serverApi)) {\n  throw new TypeError('Invalid serverApi version');\n}","typeGuard":"import { ServerApiVersion } from 'mongodb';\nfunction isServerApiVersion(v) {\n  return Object.values(ServerApiVersion).includes(typeof v === 'string' ? v : v?.version);\n}","tryCatchPattern":null,"preventionTips":["Use the ServerApiVersion.v1 constant (the string '1'), never 'v1' or a number","Reference the enum rather than hardcoding version strings","Treat version as a string at every config boundary"],"tags":["configuration","versioning","options"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}