1.Logical sessions
A logical session is a server-side identity for a sequence of related operations, created by the driver and identified by a session ID. It is not a network connection — the same session can span multiple connections, and a connection can carry operations from different sessions over time.
Key features
- Created with client.startSession() — most drivers also start one implicitly for single operations, even if the application never calls this explicitly
- A session is identified by a session ID the driver attaches to operations run through it
- Sessions enable causal consistency: within one session, later reads can be guaranteed to reflect earlier writes made in that same session
- Sessions are the mechanism retryable writes and multi-document transactions are both built on
- A session is decoupled from any one connection — the driver can route its operations over different underlying connections transparently
Command
const session = client.startSession(); /* ...operations passing { session }... */ session.endSession();A session is a server-tracked identity for a sequence of operations, independent of any one connection — it is the foundation causal consistency, retryable writes, and transactions are all built on.