{"record":{"id":"1a69910da1fa9c6b","repo":"mongodb/node-mongodb-native","slug":"illegal-profiling-level-value-was","errorCode":null,"errorMessage":"Illegal profiling level value ${was}","messagePattern":"Illegal profiling level value (.+?)","errorType":"exception","errorClass":"MongoUnexpectedServerResponseError","httpStatus":null,"severity":"error","filePath":"src/operations/profiling_level.ts","lineNumber":41,"sourceCode":"    super(db, options);\n    this.options = options;\n  }\n\n  override get commandName() {\n    return 'profile' as const;\n  }\n\n  override buildCommandDocument(_connection: Connection): Document {\n    return { profile: -1 };\n  }\n\n  override handleOk(response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>): string {\n    if (response.ok === 1) {\n      const was = response.was;\n      if (was === 0) return 'off';\n      if (was === 1) return 'slow_only';\n      if (was === 2) return 'all';\n      throw new MongoUnexpectedServerResponseError(`Illegal profiling level value ${was}`);\n    } else {\n      throw new MongoUnexpectedServerResponseError('Error with profile command');\n    }\n  }\n}\n","sourceCodeStart":23,"sourceCodeEnd":47,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/dce7939f86fb283e167ad709955abedb7bf23124/src/operations/profiling_level.ts#L23-L47","documentation":"Thrown as a MongoUnexpectedServerResponseError by ProfilingLevelOperation.handleOk when the server's 'profile' response reports ok=1 but the 'was' field is not 0, 1, or 2. Those three integers map to off/slow_only/all; any other value is an illegal profiling level that the driver cannot interpret, indicating an unexpected server response (e.g. a future or non-standard server build).","triggerScenarios":"Calling db.setProfilingLevel / db.profilingLevel and the server returns a 'was' value outside {0,1,2}. The mapping at profiling_level.ts:37-41 falls through to the throw at line 41.","commonSituations":"Connecting to a non-standard, forked, or future MongoDB build that defines extra profiling levels; corrupted/parsed response from a proxy that altered the field; middleware that rewrites command responses.","solutions":["Verify you are connecting to a genuine MongoDB server of a supported version.","Check for any proxy/middleware mangling the profile command response.","Report the unexpected 'was' value to the driver maintainers with the server version."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const level = await db.profilingLevel();\n} catch (err) {\n  if (err instanceof MongoUnexpectedServerResponseError && /Illegal profiling level value/.test(err.message)) {\n    // server returned an unrecognized 'was' value; log it and verify server build\n  } else throw err;\n}","preventionTips":["Confirm you target a genuine, supported MongoDB server version.","Check for proxies/middleware that rewrite command responses.","Log the raw 'was' value when debugging to identify the unexpected level."],"tags":["profiling","server-response","runtime","compatibility"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}