{"record":{"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/dce7939f86fb283e167ad709955abedb7bf23124/src/sessions.ts#L162-L198","documentation":"Per the Driver Sessions Spec, a session cannot be both causally consistent and a snapshot session — they use different read guarantee semantics. The ClientSession constructor throws MongoInvalidArgumentError when `options.causalConsistency === true && options.snapshot === true`.","triggerScenarios":"Calling `client.startSession({ causalConsistency: true, snapshot: true })`.","commonSituations":"Copy-pasting options between a snapshot read flow and a causal-consistency flow; enabling snapshot reads defensively while keeping causal consistency on; refactor that merges two option objects.","solutions":["Pick one mode: `{ snapshot: true }` for snapshot reads, or `{ causalConsistency: true }` (the default for explicit non-snapshot sessions) for causal consistency.","Audit option-merging code so a stale `causalConsistency: true` is not combined with a new `snapshot: true`.","Build the options object conditionally: `const opts = useSnapshot ? { snapshot: true } : { causalConsistency: true }`."],"exampleFix":"// before\nconst session = client.startSession({ causalConsistency: true, snapshot: true });\n\n// after\nconst session = client.startSession({ snapshot: true });","handlingStrategy":"validation","validationCode":"function startSession(client, opts) {\n  if (opts?.causalConsistency === true && opts?.snapshot === true) {\n    throw new TypeError('causalConsistency and snapshot are mutually exclusive');\n  }\n  return client.startSession(opts);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pick one read-consistency mode per session and document it.","Build session options from a single config object to avoid merging conflicting flags.","Add a unit test asserting your option builder never emits both flags."],"tags":["sessions","options","validation","snapshot"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}