{"id":"0ea308b1fec504b0","repo":"mongodb/node-mongodb-native","slug":"option-mongodblogpath-must-be-of-type-stderr","errorCode":null,"errorMessage":"Option 'mongodbLogPath' must be of type 'stderr' | 'stdout' | MongoDBLogWritable","messagePattern":"Option 'mongodbLogPath' must be of type 'stderr' \\| 'stdout' \\| MongoDBLogWritable","errorType":"exception","errorClass":"MongoAPIError","httpStatus":null,"severity":"error","filePath":"src/connection_string.ts","lineNumber":1247,"sourceCode":"      throw new MongoParseError(`Cannot make WriteConcern from wtimeout`);\n    }\n  },\n  zlibCompressionLevel: {\n    default: 0,\n    type: 'int'\n  },\n  mongodbLogPath: {\n    transform({ values: [value] }) {\n      if (\n        !(\n          (typeof value === 'string' && ['stderr', 'stdout'].includes(value)) ||\n          (value &&\n            typeof value === 'object' &&\n            'write' in value &&\n            typeof value.write === 'function')\n        )\n      ) {\n        throw new MongoAPIError(\n          `Option 'mongodbLogPath' must be of type 'stderr' | 'stdout' | MongoDBLogWritable`\n        );\n      }\n      return value;\n    }\n  },\n  mongodbLogComponentSeverities: {\n    transform({ values: [value] }) {\n      if (typeof value !== 'object' || !value) {\n        throw new MongoAPIError(`Option 'mongodbLogComponentSeverities' must be a non-null object`);\n      }\n      for (const [k, v] of Object.entries(value)) {\n        if (typeof v !== 'string' || typeof k !== 'string') {\n          throw new MongoAPIError(\n            `User input for option 'mongodbLogComponentSeverities' object cannot include a non-string key or value`\n          );\n        }\n        if (!Object.values(MongoLoggableComponent).some(val => val === k) && k !== 'default') {","sourceCodeStart":1229,"sourceCodeEnd":1265,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/connection_string.ts#L1229-L1265","documentation":"Thrown by the mongodbLogPath option transform when the supplied value is neither the string 'stderr', the string 'stdout', nor an object implementing a write function (MongoDBLogWritable). The driver's structured logger needs a known sink to route log output to.","triggerScenarios":"Setting mongodbLogPath to a file path string (e.g. '/var/log/mongo.log'), a number, a boolean, a Promise, or an object without a write method. Passing a Node.js fs.WriteStream directly also fails because the check requires the object itself to have a write function (WriteStream does, but a wrapper or path string does not).","commonSituations":"Assuming mongodbLogPath accepts a filesystem path like typical logging libraries; passing a Winston/pino transport object whose interface differs; enabling driver logging (mongodbLogPath is part of the newer logging API) without reading the writable contract.","solutions":["Use one of the literal strings: { mongodbLogPath: 'stderr' } or { mongodbLogPath: 'stdout' }.","Provide a writable object: { mongodbLogPath: { write: (chunk) => myStream.write(chunk) } }.","If you need a file, wrap fs.createWriteStream('./mongo.log') and pass the stream object itself (it has a write method)."],"exampleFix":"// before\nnew MongoClient(uri, { mongodbLogPath: '/var/log/mongo.log' });\n// after\nconst fs = require('fs');\nnew MongoClient(uri, { mongodbLogPath: fs.createWriteStream('/var/log/mongo.log') });","handlingStrategy":"type-guard","validationCode":"function isValidLogPath(v) {\n  return v === 'stderr' || v === 'stdout' || (v != null && typeof v === 'object' && typeof v.write === 'function');\n}","typeGuard":"function isMongoDBLogWritable(v): v is 'stderr' | 'stdout' | { write: (chunk: any) => void } {\n  return v === 'stderr' || v === 'stdout' || (!!v && typeof v === 'object' && typeof (v as any).write === 'function');\n}","tryCatchPattern":null,"preventionTips":["Remember mongodbLogPath does not accept file paths — pass 'stderr', 'stdout', or a writable object.","For file logging, wrap fs.createWriteStream and pass the stream object directly.","Type your config schema so mongodbLogPath is the literal union plus { write } interface."],"tags":["logging","options","configuration","validation"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}