mongodb/node-mongodb-native · error · MongoUnexpectedServerResponseError
Illegal profiling level value ${was}
Error message
Illegal profiling level value ${was} What it means
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.
Source
Thrown at src/operations/profiling_level.ts:41
super(db, options);
this.options = options;
}
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 3366c21a63)
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.
Defensive patterns
Strategy: try-catch
Try / catch
try {
const level = await db.getProfilingLevel();
} catch (e) {
if (e instanceof MongoUnexpectedServerResponseError && /Illegal profiling/.test(e.message)) {
// inspect raw value via db.runCommand({ profile: -1 }); possibly upgrade driver
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Error with profile command
- Error with validation data
- Profiling level must be one of "${enumToString(ProfilingLeve
- Driver attempted to initialize in load balancing mode, but t
- Current topology does not support sessions
AI-assisted analysis of mongodb/node-mongodb-native@3366c21a63 (2026-08-04).
Data as JSON: /data/errors/1a69910da1fa9c6b.json.
Report an issue: GitHub.