{"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/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/operations/profiling_level.ts#L23-L47","documentation":"Thrown by ProfilingLevelOperation.handleOk when the server's profile response reports a 'was' value that is not 0, 1, or 2. The driver maps 0->off, 1->slow_only, 2->all; any other value is unrecognized. It is a MongoUnexpectedServerResponseError, meaning the server returned data the driver cannot interpret - likely a newer/changed profiling scheme or an unusual server build.","triggerScenarios":"Calling db.getProfilingLevel() against a server that reports a profiling level outside the documented 0/1/2 set (e.g., a pre-release or fork build, or a future server version introducing new levels).","commonSituations":"Pointing the driver at a much newer server version that extended profiling levels; using a non-standard MongoDB-compatible build; driver version older than the server it is talking to.","solutions":["Check the server version with db.admin().serverInfo() and compare against the driver's compatibility matrix; upgrade the driver if the server is newer.","Run the profile command directly (db.runCommand({ profile: -1 })) to inspect the raw 'was' value returned by your server.","If the value is genuinely new, file a driver issue so the mapping can be extended.","Pin to a server version whose profiling levels the driver understands while investigating."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const level = await db.getProfilingLevel();\n} catch (e) {\n  if (e instanceof MongoUnexpectedServerResponseError && /Illegal profiling/.test(e.message)) {\n    // inspect raw value via db.runCommand({ profile: -1 }); possibly upgrade driver\n  }\n  throw e;\n}","preventionTips":["Keep the driver version compatible with the server version.","Inspect raw profile responses when integrating new server versions.","Isolate admin/monitoring calls so a response-shape change doesn't crash the app."],"tags":["profiling","admin","server-response","compatibility"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}