I’m working with mongodb 4.2.0 driver in node.js. My goal is to use client sessions (https://docs.mongodb.com/manual/reference/method/Session/) 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 (https://docs.mongodb.com/manual/core/read-isolation-consistency-recency/#client-sessions-and-causal-consistency-guarantees) 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?