{"id":"04f6d0b6352af95d","repo":"mongodb/node-mongodb-native","slug":"properties-causalconsistency-and-snapshot-are","errorCode":null,"errorMessage":"Properties \"causalConsistency\" and \"snapshot\" are mutually exclusive","messagePattern":"Properties \"causalConsistency\" and \"snapshot\" are mutually exclusive","errorType":"exception","errorClass":"MongoInvalidArgumentError","httpStatus":null,"severity":"error","filePath":"src/sessions.ts","lineNumber":180,"sourceCode":"  ) {\n    super();\n    this.on('error', noop);\n\n    if (client == null) {\n      // TODO(NODE-3483)\n      throw new MongoRuntimeError('ClientSession requires a MongoClient');\n    }\n\n    if (sessionPool == null || !(sessionPool instanceof ServerSessionPool)) {\n      // TODO(NODE-3483)\n      throw new MongoRuntimeError('ClientSession requires a ServerSessionPool');\n    }\n\n    options = options ?? {};\n\n    this.snapshotEnabled = options.snapshot === true;\n    if (options.causalConsistency === true && this.snapshotEnabled) {\n      throw new MongoInvalidArgumentError(\n        'Properties \"causalConsistency\" and \"snapshot\" are mutually exclusive'\n      );\n    }\n\n    this.client = client;\n    this.sessionPool = sessionPool;\n    this.hasEnded = false;\n    this.clientOptions = clientOptions;\n    this.timeoutMS = options.defaultTimeoutMS ?? client.s.options?.timeoutMS;\n\n    this.explicit = !!options.explicit;\n    this._serverSession = this.explicit ? this.sessionPool.acquire() : null;\n    this.txnNumberIncrement = 0;\n\n    const defaultCausalConsistencyValue = this.explicit && options.snapshot !== true;\n    this.supports = {\n      // if we can enable causal consistency, do so by default\n      causalConsistency: options.causalConsistency ?? defaultCausalConsistencyValue","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/sessions.ts#L162-L198","documentation":"Thrown by the ClientSession constructor when both `causalConsistency: true` and `snapshot: true` are passed to `startSession` (sessions.ts:179). Causal consistency and snapshot reads are distinct session semantics that cannot be combined: snapshot reads capture a single consistent point-in-time view, while causal consistency sequences reads/writes by causality.","triggerScenarios":"Calling `client.startSession({ causalConsistency: true, snapshot: true })`; merging option objects where both flags end up true.","commonSituations":"Copy-pasting session options; enabling snapshot reads for a transaction while leaving causalConsistency on; defaults from a shared config object colliding.","solutions":["Pick one: use `{ snapshot: true }` for snapshot reads or `{ causalConsistency: true }` for causal sessions.","Audit shared/default session option builders to ensure the two are not both set.","Remember causalConsistency defaults to true for explicit non-snapshot sessions, so setting snapshot requires explicitly leaving causalConsistency unset/false."],"exampleFix":"// before\nconst session = client.startSession({ causalConsistency: true, snapshot: true });\n// after\nconst session = client.startSession({ snapshot: true });","handlingStrategy":"validation","validationCode":"function sessionOptions(opts = {}) {\n  if (opts.causalConsistency === true && opts.snapshot === true) {\n    throw new TypeError('causalConsistency and snapshot are mutually exclusive');\n  }\n  return opts;\n}","typeGuard":"function areSessionOptionsCompatible(opts) {\n  return !(opts.causalConsistency === true && opts.snapshot === true);\n}","tryCatchPattern":null,"preventionTips":["Set exactly one of causalConsistency or snapshot, never both.","Centralize session option construction.","Remember causalConsistency defaults to true for explicit non-snapshot sessions."],"tags":["sessions","configuration","validation"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}