mongodb/node-mongodb-native · error · MongoUnexpectedServerResponseError
Error with profile command
Error message
Error with profile command
What it means
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.
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.
Defensive patterns
Strategy: try-catch
Try / catch
try {
const level = await db.profilingLevel();
} catch (err) {
if (err instanceof MongoUnexpectedServerResponseError && /Error with profile command/.test(err.message)) {
// likely permissions/auth; verify the user can run the profile command
} else throw err;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Illegal profiling level value
- A collection name must be determined before getMore
- A collection name must be determined before killCursors
- An unexpected error type
- Azure endpoint did not return a value with only…
AI-assisted analysis of mongodb/node-mongodb-native@dce7939f86 (2026-08-11).
Data as JSON: /api/errors/651c7baa14823e18.
Report an issue: GitHub.
Appendix: source
Thrown at src/operations/profiling_level.ts:43
}
override get commandName() {
return 'profile' as const;
}
override buildCommandDocument(_connection: Connection): Document {
return { profile: -1 };
}
override handleOk(response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>): string {
if (response.ok === 1) {
const was = response.was;
if (was === 0) return 'off';
if (was === 1) return 'slow_only';
if (was === 2) return 'all';
throw new MongoUnexpectedServerResponseError(`Illegal profiling level value ${was}`);
} else {
throw new MongoUnexpectedServerResponseError('Error with profile command');
}
}
}
View on GitHub (pinned to dce7939f86)