{"record":{"id":"2c7c66dfb0d451ff","repo":"mongodb/node-mongodb-native","slug":"snapshot-reads-require-mongodb-5-0-or-later","errorCode":null,"errorMessage":"Snapshot reads require MongoDB 5.0 or later","messagePattern":"Snapshot reads require MongoDB 5\\.0 or later","errorType":"exception","errorClass":"MongoCompatibilityError","httpStatus":null,"severity":"error","filePath":"src/operations/execute_operation.ts","lineNumber":93,"sourceCode":"    client.topology == null\n      ? await abortable(autoConnect(client), operation.options)\n      : client.topology;\n\n  // The driver sessions spec mandates that we implicitly create sessions for operations\n  // that are not explicitly provided with a session.\n  let session = operation.session;\n  let owner: symbol | undefined;\n\n  if (session == null) {\n    owner = Symbol();\n    session = client.startSession({ owner, explicit: false });\n  } else if (session.hasEnded) {\n    throw new MongoExpiredSessionError('Use of expired sessions is not permitted');\n  } else if (\n    session.snapshotEnabled &&\n    maxWireVersion(topology) < MIN_SUPPORTED_SNAPSHOT_READS_WIRE_VERSION\n  ) {\n    throw new MongoCompatibilityError('Snapshot reads require MongoDB 5.0 or later');\n  } else if (session.client !== client) {\n    throw new MongoInvalidArgumentError('ClientSession must be from the same MongoClient');\n  }\n\n  operation.session ??= session;\n\n  const readPreference = operation.readPreference ?? ReadPreference.primary;\n  const inTransaction = !!session?.inTransaction();\n\n  const hasReadAspect = operation.hasAspect(Aspect.READ_OPERATION);\n\n  if (\n    inTransaction &&\n    !readPreference.equals(ReadPreference.primary) &&\n    (hasReadAspect || operation.commandName === 'runCommand')\n  ) {\n    throw new MongoTransactionError(\n      `Read preference in a transaction must be primary, not: ${readPreference.mode}`","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/dce7939f86fb283e167ad709955abedb7bf23124/src/operations/execute_operation.ts#L75-L111","documentation":"Thrown when a session has snapshotEnabled (readConcern level 'snapshot') but the connected server's wire version is below MIN_SUPPORTED_SNAPSHOT_READS_WIRE_VERSION (13, i.e. MongoDB 5.0). Snapshot reads require server-side support for snapshot transaction semantics, so the driver refuses the operation.","triggerScenarios":"Calling client.startSession({ snapshot: true }) and running operations against a 4.4-or-earlier server; inheriting snapshot from client defaults on an older cluster.","commonSituations":"Local dev on MongoDB 4.4; connecting to an Atlas M0 tier that is pinned to an older major; upgrading the driver to a version that enables snapshot by default in some path.","solutions":["Upgrade the server to MongoDB 5.0 or later (wire version 13+).","If upgrade is not possible, omit snapshot: true from startSession options and from defaultSession options.","Verify with db.hello().maxWireVersion >= 13 before starting a snapshot session."],"exampleFix":"// before — server is 4.4\nconst session = client.startSession({ snapshot: true });\nawait collection.findOne({}, { session });\n\n// after — upgrade server to 5.0+, then the same call works","handlingStrategy":"validation","validationCode":"const hello = await db.command('hello');\nif (sessionOptions?.snapshot && hello.maxWireVersion < 13) {\n  throw new Error('Snapshot reads require MongoDB 5.0+ (wire version 13)');\n}\nconst session = client.startSession(sessionOptions);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check db.hello().maxWireVersion before starting a snapshot session.","Omit snapshot:true when targeting older servers."],"tags":["sessions","snapshot","server-version","compatibility"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}