{"id":"90ac6d92b07e2876","repo":"mongodb/node-mongodb-native","slug":"invalid-serverapi-property-must-specify-a-versi","errorCode":null,"errorMessage":"Invalid `serverApi` property; must specify a version from the following enum: [\"${Object.values(ServerApiVersion).join('\", \"')}\"]","messagePattern":"Invalid `serverApi` property; must specify a version from the following enum: \\[\"(.+?)\"\\]","errorType":"exception","errorClass":"MongoParseError","httpStatus":null,"severity":"error","filePath":"src/connection_string.ts","lineNumber":758,"sourceCode":"  },\n  autoSelectFamily: {\n    type: 'boolean',\n    default: true\n  },\n  autoSelectFamilyAttemptTimeout: {\n    type: 'uint'\n  },\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  },","sourceCodeStart":740,"sourceCodeEnd":776,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/connection_string.ts#L740-L776","documentation":"The `serverApi` option requires a version. You may pass a string (treated as `{ version }`) or an object with a `version` field. The transform (src/connection_string.ts:751-772) derives `versionToValidate`; if it is missing or falsy, the driver throws because it cannot pin an API version.","triggerScenarios":"`{ serverApi: {} }`; `{ serverApi: { version: undefined } }`; `{ serverApi: { version: '' } }`; `{ serverApi: null }`.","commonSituations":"Building serverApi dynamically and letting version be undefined; spreading a config object that omits version; conditional config that drops the key.","solutions":["Set `serverApi: ServerApiVersion.v1` (currently the only supported version)","Or `serverApi: { version: ServerApiVersion.v1 }`","Ensure dynamically-built config always includes a truthy version"],"exampleFix":"// before\nnew MongoClient(uri, { serverApi: {} });\n// after\nimport { ServerApiVersion } from 'mongodb';\nnew MongoClient(uri, { serverApi: ServerApiVersion.v1 });","handlingStrategy":"validation","validationCode":"import { ServerApiVersion } from 'mongodb';\nfunction hasServerApiVersion(v) {\n  const o = typeof v === 'string' ? { version: v } : v;\n  return !!o && typeof o.version === 'string' && o.version.length > 0;\n}\nif (options.serverApi && !hasServerApiVersion(options.serverApi)) {\n  throw new TypeError('serverApi must specify a version');\n}","typeGuard":"import { ServerApiVersion } from 'mongodb';\nfunction isServerApiLike(v) {\n  const o = typeof v === 'string' ? { version: v } : v;\n  return !!o && typeof o === 'object' && typeof o.version === 'string';\n}","tryCatchPattern":null,"preventionTips":["Always set serverApi to ServerApiVersion.v1","When building config dynamically, default version to ServerApiVersion.v1","Avoid spreading partial config objects into serverApi"],"tags":["configuration","versioning","options"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}