{"record":{"id":"23dbed48f82af6d1","repo":"mongodb/node-mongodb-native","slug":"unable-to-include-driverinfo-name-and-version-met","errorCode":null,"errorMessage":"Unable to include driverInfo name and version, metadata cannot exceed 512 bytes","messagePattern":"Unable to include driverInfo name and version, metadata cannot exceed 512 bytes","errorType":"exception","errorClass":"MongoInvalidArgumentError","httpStatus":null,"severity":"error","filePath":"src/cmap/handshake/client_metadata.ts","lineNumber":140,"sourceCode":"  }\n\n  const driverInfo = {\n    name: 'nodejs',\n    version: NODE_DRIVER_VERSION\n  };\n\n  // This is where we handle additional driver info added after client construction.\n  for (const { name: n = '', version: v = '' } of driverInfoList) {\n    if (n.length > 0) {\n      driverInfo.name = `${driverInfo.name}|${n}`;\n    }\n    if (v.length > 0) {\n      driverInfo.version = `${driverInfo.version}|${v}`;\n    }\n  }\n\n  if (!metadataDocument.ifItFitsItSits('driver', driverInfo)) {\n    throw new MongoInvalidArgumentError(\n      'Unable to include driverInfo name and version, metadata cannot exceed 512 bytes'\n    );\n  }\n\n  let runtimeInfo = getRuntimeInfo();\n  // This is where we handle additional driver info added after client construction.\n  for (const { platform = '' } of driverInfoList) {\n    if (platform.length > 0) {\n      runtimeInfo = `${runtimeInfo}|${platform}`;\n    }\n  }\n\n  if (!metadataDocument.ifItFitsItSits('platform', runtimeInfo)) {\n    throw new MongoInvalidArgumentError(\n      'Unable to include driverInfo platform, metadata cannot exceed 512 bytes'\n    );\n  }\n","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/dce7939f86fb283e167ad709955abedb7bf23124/src/cmap/handshake/client_metadata.ts#L122-L158","documentation":"A MongoInvalidArgumentError thrown in makeClientMetadata when the driver info (name + version) alone cannot fit within the 512-byte BSON limit for client metadata sent during the handshake. The driver first adds application name, then the driver block; if even the driver block overflows 512 bytes, the handshake metadata cannot be constructed and the client refuses to connect.","triggerScenarios":"Providing a driverInfo.name and/or driverInfo.version via MongoClient options whose combined BSON-encoded size (plus application name) exceeds 512 bytes. The driver name accumulates segments like 'nodejs|<yourName>' and version 'x.y.z|<yourVersion>'.","commonSituations":"Passing very long company/product identifiers in driverInfo.name; long version strings with many segments; a long appName consuming most of the 512-byte budget; multiple middleware layers each appending driverInfo.","solutions":["Shorten the driverInfo.name and driverInfo.version strings.","Shorten appName to leave room for driver metadata.","Avoid stacking multiple driverInfo contributors with long identifiers.","Validate driverInfo length at app startup."],"exampleFix":"// before\nconst client = new MongoClient(uri, {\n  appName: 'x'.repeat(200),\n  driverInfo: { name: 'a'.repeat(300), version: 'b'.repeat(300) }\n});\n\n// after\nconst client = new MongoClient(uri, {\n  appName: 'my-app',\n  driverInfo: { name: 'my-driver', version: '1.0.0' }\n});","handlingStrategy":"validation","validationCode":"function byteLength(s: string) { return Buffer.byteLength(s, 'utf8'); }\nconst total = byteLength(appName) + byteLength(driverInfo.name) + byteLength(driverInfo.version);\nif (total > 400) {\n  throw new Error('driverInfo + appName too large for 512-byte metadata limit');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep driverInfo.name/version short.","Keep appName under 128 bytes.","Validate metadata size at startup."],"tags":["handshake","metadata","config","startup"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}