{"id":"e067d92c385bcfad","repo":"mongodb/node-mongodb-native","slug":"proxy-options-cannot-be-specified-multiple-times-i","errorCode":null,"errorMessage":"Proxy options cannot be specified multiple times in the connection string","messagePattern":"Proxy options cannot be specified multiple times in the connection string","errorType":"exception","errorClass":"MongoParseError","httpStatus":null,"severity":"error","filePath":"src/connection_string.ts","lineNumber":523,"sourceCode":"    !mongoOptions.proxyHost &&\n    (mongoOptions.proxyPort || mongoOptions.proxyUsername || mongoOptions.proxyPassword)\n  ) {\n    throw new MongoParseError('Must specify proxyHost if other proxy options are passed');\n  }\n\n  if (\n    (mongoOptions.proxyUsername && !mongoOptions.proxyPassword) ||\n    (!mongoOptions.proxyUsername && mongoOptions.proxyPassword)\n  ) {\n    throw new MongoParseError('Can only specify both of proxy username/password or neither');\n  }\n\n  const proxyOptions = ['proxyHost', 'proxyPort', 'proxyUsername', 'proxyPassword'].map(\n    key => urlOptions.get(key) ?? []\n  );\n\n  if (proxyOptions.some(options => options.length > 1)) {\n    throw new MongoParseError(\n      'Proxy options cannot be specified multiple times in the connection string'\n    );\n  }\n\n  mongoOptions.mongoLoggerOptions = MongoLogger.resolveOptions(\n    {\n      MONGODB_LOG_COMMAND: process.env.MONGODB_LOG_COMMAND,\n      MONGODB_LOG_TOPOLOGY: process.env.MONGODB_LOG_TOPOLOGY,\n      MONGODB_LOG_SERVER_SELECTION: process.env.MONGODB_LOG_SERVER_SELECTION,\n      MONGODB_LOG_CONNECTION: process.env.MONGODB_LOG_CONNECTION,\n      MONGODB_LOG_CLIENT: process.env.MONGODB_LOG_CLIENT,\n      MONGODB_LOG_ALL: process.env.MONGODB_LOG_ALL,\n      MONGODB_LOG_MAX_DOCUMENT_LENGTH: process.env.MONGODB_LOG_MAX_DOCUMENT_LENGTH,\n      MONGODB_LOG_PATH: process.env.MONGODB_LOG_PATH\n    },\n    {\n      mongodbLogPath: mongoOptions.mongodbLogPath,\n      mongodbLogComponentSeverities: mongoOptions.mongodbLogComponentSeverities,","sourceCodeStart":505,"sourceCodeEnd":541,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/connection_string.ts#L505-L541","documentation":"Thrown when any of the proxy URI query parameters (proxyHost, proxyPort, proxyUsername, proxyPassword) appears more than once in the connection string (connection_string.ts:518-526). Unlike readPreferenceTags, the proxy options are scalar and must not be repeated; the driver refuses to guess which value wins.","triggerScenarios":"URI like 'mongodb://host/?proxyHost=p1&proxyHost=p2' or appending proxy params twice in a config builder.","commonSituations":"A config templating layer concatenating URI fragments that each include proxy options; misconfigured secret injection that appends rather than sets.","solutions":["Ensure each proxy parameter appears at most once in the URI.","Inspect how the URI is assembled (URLSearchParams.append vs set) and prefer set.","Consolidate proxy configuration into the options object instead of the URI."],"exampleFix":"// before\nconst uri = 'mongodb://host/?proxyHost=p1&proxyHost=p2';\n// after\nconst uri = 'mongodb://host/?proxyHost=p1';","handlingStrategy":"validation","validationCode":"const params = new URLSearchParams(new URL(uri).search);\nfor (const k of ['proxyHost', 'proxyPort', 'proxyUsername', 'proxyPassword']) {\n  if (params.getAll(k).length > 1) throw new Error(`Proxy option ${k} appears more than once in the URI`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build query strings with URLSearchParams.set, not append, for scalar options.","Centralize URI construction instead of string concatenation."],"tags":["connection-string","proxy","configuration"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}