{"record":{"id":"10bef45c7abf8fbb","repo":"mongodb/node-mongodb-native","slug":"bson-element-name-is-missing","errorCode":null,"errorMessage":"BSON element \"${name}\" is missing","messagePattern":"BSON element \"(.+?)\" is missing","errorType":"exception","errorClass":"BSONError","httpStatus":null,"severity":"error","filePath":"src/cmap/wire_protocol/on_demand/document.ts","lineNumber":286,"sourceCode":"    required?: boolean\n  ): JSTypeOf[T] | null;\n\n  /** `required` will make `get` throw if name does not exist or is null/undefined */\n  public get<const T extends keyof JSTypeOf>(\n    name: string | number,\n    as: T,\n    required: true\n  ): JSTypeOf[T];\n\n  public get<const T extends keyof JSTypeOf>(\n    name: string | number,\n    as: T,\n    required?: boolean\n  ): JSTypeOf[T] | null {\n    const element = this.getElement(name);\n    if (element == null) {\n      if (required === true) {\n        throw new BSONError(`BSON element \"${name}\" is missing`);\n      } else {\n        return null;\n      }\n    }\n\n    if (element.value == null) {\n      const value = this.toJSValue(element.element, as);\n      if (value == null) {\n        if (required === true) {\n          throw new BSONError(`BSON element \"${name}\" is missing`);\n        } else {\n          return null;\n        }\n      }\n      // It is important to never store null\n      element.value = value;\n    }\n","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/dce7939f86fb283e167ad709955abedb7bf23124/src/cmap/wire_protocol/on_demand/document.ts#L268-L304","documentation":"Thrown by OnDemandDocument.get when an element with the requested name does not exist AND the caller passed required=true. It is a BSONError indicating a mandatory field is absent from the BSON document. Because OnDemandDocument is @internal, this fires inside driver code that asserts a field the server is contractually expected to return.","triggerScenarios":"Fires at src/cmap/wire_protocol/on_demand/document.ts:286 when getElement(name) returns null and required is true. Reachable through any internal call site using get(..., true), typically while parsing SDAM, command, or cursor responses.","commonSituations":"Server version that omits a field the driver expects (version skew); a proxy stripping fields; a corrupted response; pointing a newer driver at a much older server. When surfaced through MongoDBResponse.get it is wrapped as MongoUnexpectedServerResponseError (see error 149).","solutions":["Ensure the server version meets the driver's minimum supported version.","Upgrade the driver and server to compatible releases.","Remove any intermediate that alters server responses.","Report the unexpected response shape to the driver team."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await client.db().admin().command({ hello: 1 });\n} catch (e) {\n  if (e instanceof MongoUnexpectedServerResponseError) {\n  }\n}","preventionTips":["Confirm server version meets the driver minimum.","Upgrade driver and server together.","Do not place response-altering proxies in the path."],"tags":["bson","driver-internal","version-mismatch","wire-protocol"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}