{"record":{"id":"f1f1684eb9a33bb5","repo":"mongodb/node-mongodb-native","slug":"unsupported-bson-type-as","errorCode":null,"errorMessage":"Unsupported BSON type: ${as}","messagePattern":"Unsupported BSON type: (.+?)","errorType":"exception","errorClass":"BSONError","httpStatus":null,"severity":"error","filePath":"src/cmap/wire_protocol/on_demand/document.ts","lineNumber":230,"sourceCode":"          );\n        }\n\n        return new Binary(\n          this.bson.subarray(offset + 1 + 4, offset + 1 + 4 + totalBinarySize),\n          subType\n        );\n      }\n      case BSONType.date:\n        // Pretend this is correct.\n        return new Date(Number(NumberUtils.getBigInt64LE(this.bson, offset)));\n\n      case BSONType.object:\n        return new OnDemandDocument(this.bson, offset);\n      case BSONType.array:\n        return new OnDemandDocument(this.bson, offset, true);\n\n      default:\n        throw new BSONError(`Unsupported BSON type: ${as}`);\n    }\n  }\n\n  /**\n   * Returns the number of elements in this BSON document\n   */\n  public size() {\n    return this.elements.length;\n  }\n\n  /**\n   * Checks for the existence of an element by name.\n   *\n   * @remarks\n   * Uses `getElement` with the expectation that will populate caches such that a `has` call\n   * followed by a `getElement` call will not repeat the cost paid by the first look up.\n   *\n   * @param name - element name","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/dce7939f86fb283e167ad709955abedb7bf23124/src/cmap/wire_protocol/on_demand/document.ts#L212-L248","documentation":"Thrown by the OnDemandDocument.toJSValue switch when it is asked to materialize a BSON type it does not handle (the default case). The driver's on-demand reader only supports the subset of BSON types needed for its own internals (null, numbers, bool, objectId, timestamp, string, binData, date, object, array). If driver code requests a type outside that set (e.g. regex, javascript, decimal128, dbPointer), it throws a BSONError. This is an internal-programming-error path, not a user-input path.","triggerScenarios":"Fires at src/cmap/wire_protocol/on_demand/document.ts:230 only when toJSValue is called with an `as` BSON type constant that matches the element's type but is absent from the switch cases. Because the public API never exposes toJSValue (@internal class), a user seeing this means driver internals attempted to read an unsupported type from a server response.","commonSituations":"A driver version mismatch where new server response fields carry BSON types the on-demand reader cannot parse; a regression in driver internals; a prerelease server adding response fields of unsupported types. Extremely rare for end users.","solutions":["Upgrade the mongodb driver to the latest version.","Upgrade mongod/mongos to a mutually compatible version.","Report the issue to the driver team with the command and server version that triggered it."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await client.connect();\n} catch (e) {\n  if (e instanceof BSONError && /Unsupported BSON type/.test(e.message)) {\n  }\n}","preventionTips":["Keep the driver version current.","Match driver and server versions per the compatibility matrix.","Avoid prerelease servers with stable drivers."],"tags":["bson","driver-internal","version-mismatch","parsing"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}