-
Type: Spec Change
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Component/s: Sessions
-
None
-
Needed
TLDR: "startSession MAY report an error if sessions are not supported by the deployment (see How to Check Whether a Deployment Supports Sessions)."
The drive sessions spec currently indicates that
startSession MUST report an error if sessions are not supported by the deployment (see How to Check Whether a Deployment Supports Sessions).
I think this language constricts design, and should be loosened to a MAY. Generally, all startSession does is creates a local session id (it used to be a command, which could justify the requirement), it does not do any I/O and therefore I think we should be able to defer the potential server selection to the time of operation execution.
For async drivers (such as node) the current prose would require that the method be asynchronous, turning this code:
MongoClient.connect('mongodb://localhost/test').then(client => { const session = client.startSession({ causalConsistency: true }); const coll = client.db('foo').collection('bar'); return coll.insert({ a: 42 }, { session: session }) });
into:
MongoClient.connect('mongodb://localhost/test').then(client => { client.startSession({ causalConsistency: true }).then(session => { const coll = client.db('foo').collection('bar'); return coll.insert({ a: 42 }, { session: session }); }); });
While this is purely a cosmetic complaint at this point, I think the deeper level here is the concern about locality of the session support check. Driver sessions also require that implicit sessions be created for all operations where an explicit session has not been provided. This means that the check for topology sessions support must also happen in the implicit case. If we defer the check in startSession to the point of operation execution, we can use the same path to determine session support for both explicit and implicit cases.