mongodb/node-mongodb-native · error · MongoCompatibilityError
Snapshot reads require MongoDB 5.0 or later
Error message
Snapshot reads require MongoDB 5.0 or later
What it means
executeOperation (src/operations/execute_operation.ts:93) throws a MongoCompatibilityError when a session with snapshot reads enabled (startSession({ snapshot: true })) is used against a server whose wire version is below MIN_SUPPORTED_SNAPSHOT_READS_WIRE_VERSION, i.e. a server older than MongoDB 5.0. Snapshot sessions are a server feature introduced in 5.0 and cannot be emulated by the driver.
Source
Thrown at src/operations/execute_operation.ts:93
client.topology == null
? await abortable(autoConnect(client), operation.options)
: client.topology;
// The driver sessions spec mandates that we implicitly create sessions for operations
// that are not explicitly provided with a session.
let session = operation.session;
let owner: symbol | undefined;
if (session == null) {
owner = Symbol();
session = client.startSession({ owner, explicit: false });
} else if (session.hasEnded) {
throw new MongoExpiredSessionError('Use of expired sessions is not permitted');
} else if (
session.snapshotEnabled &&
maxWireVersion(topology) < MIN_SUPPORTED_SNAPSHOT_READS_WIRE_VERSION
) {
throw new MongoCompatibilityError('Snapshot reads require MongoDB 5.0 or later');
} else if (session.client !== client) {
throw new MongoInvalidArgumentError('ClientSession must be from the same MongoClient');
}
operation.session ??= session;
const readPreference = operation.readPreference ?? ReadPreference.primary;
const inTransaction = !!session?.inTransaction();
const hasReadAspect = operation.hasAspect(Aspect.READ_OPERATION);
if (
inTransaction &&
!readPreference.equals(ReadPreference.primary) &&
(hasReadAspect || operation.commandName === 'runCommand')
) {
throw new MongoTransactionError(
`Read preference in a transaction must be primary, not: ${readPreference.mode}`View on GitHub (pinned to 3366c21a63)
Solutions
- Upgrade the MongoDB deployment to 5.0 or later — snapshot reads require it.
- If upgrade is not possible, remove the snapshot:true option from startSession.
- Verify the deployment version with a hello/buildInfo command to confirm compatibility before enabling the feature.
Example fix
// before
const session = client.startSession({ snapshot: true }); // on MongoDB 4.4
// after (upgrade server, or remove snapshot)
const session = client.startSession(); // no snapshot on < 5.0
// or upgrade the deployment to >= 5.0 and keep snapshot:true Defensive patterns
Strategy: validation
Validate before calling
// Check server version before enabling snapshot reads
const admin = client.db().admin();
const buildInfo = await admin.command({ buildInfo: 1 });
const major = parseInt(buildInfo.versionArray[0], 10);
const snapshotOk = major >= 5;
const session = client.startSession(snapshotOk ? { snapshot: true } : {}); Prevention
- Confirm the deployment is MongoDB 5.0+ before using snapshot reads.
- Gate snapshot-enabled code behind a version check.
- Upgrade test/dev environments to match production versions.
When it happens
Trigger: Calling client.startSession({ snapshot: true }) and using it against a standalone, replica set, or sharded cluster running MongoDB 4.4 or earlier.
Common situations: Upgrading the driver to use snapshot reads while the deployment has not been upgraded to 5.0+, or pointing a snapshot-enabled app at a legacy test/dev instance.
Related errors
- Transactions are not supported in snapshot sessions
- Driver attempted to initialize in load balancing mode, but t
- Current topology does not support sessions
- Unexpected null session. A cursor creating command should ha
- Unexpected null session. A cursor creating command should ha
AI-assisted analysis of mongodb/node-mongodb-native@3366c21a63 (2026-08-04).
Data as JSON: /data/errors/2c7c66dfb0d451ff.json.
Report an issue: GitHub.