{"record":{"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/dce7939f86fb283e167ad709955abedb7bf23124/src/connection_string.ts#L740-L776","documentation":"Thrown by MongoParseError at src/connection_string.ts:758 in the `serverApi` transform when the supplied value has no `version` field. The driver requires a `version` matching the `ServerApiVersion` enum (currently only `'1'`). The message lists the accepted enum values. Triggered whether you pass a string, an object, or `undefined` for version.","triggerScenarios":"`{ serverApi: {} }`, `{ serverApi: { strict: true } }` (missing version), or `{ serverApi: '' }`.","commonSituations":"Wanting to enable strict mode and passing only `{ strict: true }`; reading serverApi from config where the version key is absent.","solutions":["Always include `version`: `{ serverApi: { version: ServerApiVersion.v1, strict: true, deprecationErrors: true } }`.","Or pass the bare version string `{ serverApi: ServerApiVersion.v1 }` which the driver wraps as `{ version }`.","Import `ServerApiVersion` from 'mongodb' rather than hard-coding the string."],"exampleFix":"// before\nnew MongoClient(uri, { serverApi: { strict: true, deprecationErrors: true } })\n\n// after\nimport { ServerApiVersion } from 'mongodb'\nnew MongoClient(uri, { serverApi: { version: ServerApiVersion.v1, strict: true, deprecationErrors: true } })","handlingStrategy":"validation","validationCode":"function assertServerApiHasVersion(serverApi) { if (!serverApi) return; const v = typeof serverApi === 'string' ? serverApi : serverApi.version; if (!v) throw new Error('serverApi.version is required.'); }","typeGuard":"import { ServerApiVersion } from 'mongodb';\nfunction hasServerApiVersion(v): boolean { if (v == null) return false; if (typeof v === 'string') return true; return typeof v === 'object' && typeof v.version === 'string'; }","tryCatchPattern":"try { new MongoClient(uri, { serverApi }); } catch (e) { if (e instanceof MongoParseError && /Invalid `serverApi` property/.test(e.message)) { serverApi = { version: ServerApiVersion.v1, ...serverApi }; } else throw e; }","preventionTips":["Always include `version` when constructing the serverApi object.","Use the bare-string form `{ serverApi: ServerApiVersion.v1 }` for the simplest case."],"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"}