Parallel Writes/Reads in a client Session in Node

I’m working with mongodb 4.2.0 driver in node.js. My goal is to use client sessions ( to enable causal consistency and ensure that my application reads back its own writes, despite having global read nodes and a single write region. After turning on client sessions and switching connection from primary to nearest node, we noticed some writes silently failed (despite receiving “OK”). Others failed with an explicit error like “Retryable write with txnNumber 1 is prohibited on session because a newer retryable write with txnNumber 2 has already started on this session.”. So to address this, we tried to automatically batch all of our writes (via bulkWrite), but still noticed the error happening. We also noticed in the documentation ( that “Applications must ensure that only one thread at a time executes these operations in a client session.”. Since node is single-threaded I assumed this would be fine, but I’m wondering if async is counting as “more than one thread”?

Any advice on getting client sessions with causal consistency working on Node? I can try disabling retryable writes, but just wondering how many more undocumented things like this I might run into. For example, can I issue reads in parallel safely in a client session?

Hi there, have you found a solution?

I was checking the documentation and noticed 2 important lines:

Causally consistent sessions can only guarantee causal consistency for reads with "majority" read concern and writes with "majority" write concern.

To provide causal consistency … Applications must ensure that only one thread at a time executes these operations in a client session

do these lines apply to your situation?