@@ -63,24 +63,28 @@ response. The `atClusterTime` field represents the timestamp of the read and is
6363## Specification
6464
6565An application requests snapshot reads by creating a ` ClientSession ` with options that specify that snapshot reads are
66- desired. An application then passes the session as an argument to methods in the ` MongoDatabase ` and ` MongoCollection `
67- classes. Read operations (find/aggregate/distinct) performed against that session will be read from the same snapshot.
66+ desired and optionally specifying a ` snapshotTime ` . An application then passes the session as an argument to methods in
67+ the ` MongoDatabase ` and ` MongoCollection ` classes. Read operations (find/aggregate/distinct) performed against that
68+ session will be read from the same snapshot.
6869
6970## High level summary of the API changes for snapshot reads
7071
7172Snapshot reads are built on top of client sessions.
7273
73- Applications will start a new client session for snapshot reads like this:
74+ Applications will start a new client session for snapshot reads and possibly retrieve the snapshot time like this:
7475
7576``` typescript
76- options = new SessionOptions (snapshot = true );
77+ options = new SessionOptions (snapshot = true , snapshotTime = timestampValue );
7778session = client .startSession (options );
79+ snapshotTime = session .snapshotTime ;
7880```
7981
8082All read operations performed using this session will be read from the same snapshot.
8183
82- If no value is provided for ` snapshot ` a value of false is implied. There are no MongoDatabase, MongoClient, or
83- MongoCollection API changes.
84+ If no value is provided for ` snapshot ` a value of false is implied. ` snapshotTime ` is an optional parameter and if not
85+ passed the snapshot time will be set internally after the first find/aggregate/distinct operation inside the session.
86+
87+ There are no MongoDatabase, MongoClient, or MongoCollection API changes.
8488
8589## SessionOptions changes
8690
@@ -89,14 +93,16 @@ MongoCollection API changes.
8993``` typescript
9094class SessionOptions {
9195 Optional < bool > snapshot;
96+ Optional < BsonTimestamp > snapshotTime;
9297
9398 // other options defined by other specs
9499}
95100```
96101
97- In order to support snapshot reads a new property named ` snapshot ` is added to ` SessionOptions ` . Applications set
98- ` snapshot ` when starting a client session to indicate whether they want snapshot reads. All read operations performed
99- using that client session will share the same snapshot.
102+ In order to support snapshot reads two properties called ` snapshot ` and ` snapshotTime ` are added to ` SessionOptions ` .
103+ Applications set ` snapshot ` when starting a client session to indicate whether they want snapshot reads and optionally
104+ set ` snapshotTime ` to specify the desired snapshot time beforehand. All read operations performed using that client
105+ session will share the same snapshot.
100106
101107Each new member is documented below.
102108
@@ -110,8 +116,29 @@ Snapshot reads and causal consistency are mutually exclusive. Therefore if `snap
110116` causalConsistency ` must be false. Client MUST throw an error if both ` snapshot ` and ` causalConsistency ` are set to
111117true. Snapshot reads are supported on both primaries and secondaries.
112118
119+ ### snapshotTime
120+
121+ Applications set ` snapshotTime ` when starting a snapshot session to specify the desired snapshot time.
122+
123+ Note that the ` snapshotTime ` property is optional. The default value of this property is null.
124+
125+ Client MUST throw an error if ` snapshotTime ` is set and ` snapshot ` is not set to true.
126+
113127## ClientSession changes
114128
129+ A readonly property called ` snapshotTime ` will be added to ` ClientSession ` that allows applications to retrieve the
130+ snapshot time of the session:
131+
132+ ``` typescript
133+ class ClientSession {
134+ readonly Optional < BsonTimestamp > snapshotTime;
135+
136+ // other options defined by other specs
137+ }
138+ ```
139+
140+ Getting the value of ` snapshotTime ` on a non-snapshot session MUST raise an error.
141+
115142Transactions are not allowed with snapshot sessions. Calling ` session.startTransaction(options) ` on a snapshot session
116143MUST raise an error.
117144
@@ -123,10 +150,12 @@ MUST raise an error.
123150
124151There are no new server commands related to snapshot reads. Instead, snapshot reads are implemented by:
125152
126- 1 . Saving the ` atClusterTime ` returned by 5.0+ servers for the first find/aggregate/distinct operation in a private
127- ` snapshotTime ` property of the ` ClientSession ` object. Drivers MUST save ` atClusterTime ` in the ` ClientSession `
128- object.
129- 2 . Passing that ` snapshotTime ` in the ` atClusterTime ` field of the ` readConcern ` field for subsequent snapshot read
153+ 1 . If ` snapshotTime ` is specified in ` SessionOptions ` , saving the value in a ` snapshotTime ` property of the
154+ ` ClientSession ` .
155+ 2 . If ` snapshotTime ` is not specified in ` SessionOptions ` , saving the ` atClusterTime ` returned by 5.0+ servers for the
156+ first find/aggregate/distinct operation in a ` snapshotTime ` property of the ` ClientSession ` object. Drivers MUST
157+ save ` atClusterTime ` in the ` ClientSession ` object.
158+ 3 . Passing that ` snapshotTime ` in the ` atClusterTime ` field of the ` readConcern ` field for subsequent snapshot read
130159 operations (i.e. find/aggregate/distinct commands).
131160
132161## Server Command Responses
@@ -241,6 +270,7 @@ C# driver will provide the reference implementation. The corresponding ticket is
241270
242271## Changelog
243272
273+ - 2025-09-23: Exposed snapshotTime to applications.
244274- 2024-05-08: Migrated from reStructuredText to Markdown.
245275- 2021-06-15: Initial version.
246276- 2021-06-28: Raise client side error on < 5.0.
0 commit comments