mongodb/node-mongodb-native · error · MongoParseError
ReadConcern must be an object, got ${JSON.stringify(value)}
Error message
ReadConcern must be an object, got ${JSON.stringify(value)} What it means
The `readConcern` option must be a `ReadConcern` instance or a plain object containing a `level` key. The transform (src/connection_string.ts:991-997) checks `value instanceof ReadConcern || isRecord(value, ['level'])`; any other shape throws.
Source
Thrown at src/connection_string.ts:996
proxyPassword: {
type: 'string'
},
proxyPort: {
type: 'uint'
},
proxyUsername: {
type: 'string'
},
raw: {
default: false,
type: 'boolean'
},
readConcern: {
transform({ values: [value], options }) {
if (value instanceof ReadConcern || isRecord(value, ['level'] as const)) {
return ReadConcern.fromOptions({ ...options.readConcern, ...value });
}
throw new MongoParseError(`ReadConcern must be an object, got ${JSON.stringify(value)}`);
}
},
readConcernLevel: {
target: 'readConcern',
transform({ values: [level], options }) {
return ReadConcern.fromOptions({
...options.readConcern,
level: level as ReadConcernLevel
});
}
},
readPreference: {
default: ReadPreference.primary,
transform({ values: [value], options }) {
if (value instanceof ReadPreference) {
return ReadPreference.fromOptions({
readPreference: { ...options.readPreference, ...value },
...valueView on GitHub (pinned to 3366c21a63)
Solutions
- Use `readConcern: { level: 'local' }` (valid levels: 'local','available','majority','linearizable','snapshot')
- Or use the `readConcernLevel: 'local'` option which takes the string directly
- Use `new ReadConcern('local')`
Example fix
// before
new MongoClient(uri, { readConcern: 'local' });
// after
new MongoClient(uri, { readConcernLevel: 'local' });
// or
new MongoClient(uri, { readConcern: { level: 'local' } }); Defensive patterns
Strategy: type-guard
Validate before calling
import { ReadConcern } from 'mongodb';
function isReadConcernLike(v) {
return v instanceof ReadConcern || (v != null && typeof v === 'object' && 'level' in v);
}
if (options.readConcern && !isReadConcernLike(options.readConcern)) {
throw new TypeError('readConcern must be { level } or a ReadConcern');
} Type guard
import { ReadConcern } from 'mongodb';
function isReadConcernLike(v) {
return v instanceof ReadConcern || (!!v && typeof v === 'object' && 'level' in v);
} Prevention
- Use { level: '...' } or the readConcernLevel shorthand
- Do not pass a bare level string to readConcern
- Distinguish readConcern (durability/consistency) from readPreference (routing)
When it happens
Trigger: `{ readConcern: 'local' }` (string — should be `{ level: 'local' }` or use `readConcernLevel`); `{ readConcern: 1 }`; `{ readConcern: ['local'] }`.
Common situations: Passing a level string directly instead of an object; confusing `readConcern` with the `readConcernLevel` shorthand; mixing up with read preference.
Related errors
- Descriptors missing a type must define a transform
- ${name} must be an object with 'username' and 'password' pro
- authMechanism one of ${mechanisms}, got ${value}
- Invalid `serverApi` property; must specify a version from th
- Invalid server API version=${versionToValidate}; must be in
AI-assisted analysis of mongodb/node-mongodb-native@3366c21a63 (2026-08-04).
Data as JSON: /data/errors/30e9801cb0750d03.json.
Report an issue: GitHub.