{"record":{"id":"651c7baa14823e18","repo":"mongodb/node-mongodb-native","slug":"error-with-profile-command","errorCode":null,"errorMessage":"Error with profile command","messagePattern":"Error with profile command","errorType":"exception","errorClass":"MongoUnexpectedServerResponseError","httpStatus":null,"severity":"error","filePath":"src/operations/profiling_level.ts","lineNumber":43,"sourceCode":"  }\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":25,"sourceCodeEnd":47,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/dce7939f86fb283e167ad709955abedb7bf23124/src/operations/profiling_level.ts#L25-L47","documentation":"Thrown as a MongoUnexpectedServerResponseError by ProfilingLevelOperation.handleOk when the server's 'profile' command response has ok !== 1. An ok value other than 1 means the command did not succeed at the protocol level, yet no error was surfaced through the normal error path, so the driver reports a generic profile-command error.","triggerScenarios":"Calling db.profilingLevel() (which sends {profile: -1}) and the server returns ok=0 or another non-1 value in the response body, bypassing the wire-level error handling.","commonSituations":"Server-side refusal to run the profile command for non-obvious reasons; a proxy or mock returning a malformed ok field; driver/server version skew in response shaping.","solutions":["Inspect server logs for why the profile command returned ok != 1 (often auth or permissions on admin-only command).","Ensure the connected user has privileges to run the profile command (typically requires admin/dbAdmin on the database).","Confirm the target is a genuine MongoDB deployment."],"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 && /Error with profile command/.test(err.message)) {\n    // likely permissions/auth; verify the user can run the profile command\n  } else throw err;\n}","preventionTips":["Ensure the connected user has admin/dbAdmin privileges needed for the profile command.","Check server logs for command-level refusals.","Confirm the deployment is a real MongoDB instance."],"tags":["profiling","server-response","runtime","permissions"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}