-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: Sessions
-
3
-
-
None
-
None
-
None
-
None
-
None
-
None
-
None
This ticket was split from DRIVERS-2782, please see that ticket for a detailed description.
Overview
The specification change (DRIVERS-2782) exposes snapshotTime to applications, allowing them to:
- Set a snapshotTime when creating a snapshot session
- Get the snapshotTime from an existing snapshot session
Why we should make this change
MongoDB allows users to read data from a specific point in time (called a snapshot). Right now, the timestamp marking that point in time (atClusterTime) is a non-public prop inside the Session and can't be accessed or reused. This prevents common scenarios like ensuring different services see the same snapshot of data, or running long processes that need consistent reads throughout. By exposing atClusterTime, users can capture that timestamp from one session and use it to create new sessions with the same snapshot, something customers have been requesting but can't do today.
Proposed Implementation Changes
- Add snapshotTime to ClientSessionOptions interface (src/sessions.ts)
- Expose snapshotTime as a public readonly property on ClientSession
- Update ClientSession constructor logic
- Add validation in constructor
- Update unified test runner (for test support)
- Add prose tests (test/integration or test/manual)
Sample Code Changes
Change 1: Update ClientSessionOptions interface
// node-mongodb-native/src/sessions.ts export interface ClientSessionOptions { causalConsistency?: boolean; snapshot?: boolean; snapshotTime?: Timestamp; // ADD THIS defaultTransactionOptions?: TransactionOptions; // ... other options }
Change 2: Update ClientSession class
export class ClientSession { // Change from @internal to public public readonly snapshotTime?: Timestamp; // MAKE PUBLIC // Add getter with validation get snapshotTime(): Timestamp | undefined { if (!this.snapshotEnabled){ throw new MongoInvalidArgumentError( 'snapshotTime can only be accessed on snapshot sessions' ); } return this._snapshotTime; } }
Acceptance Criteria
- Implementation follows the Snapshot Sessions Specification
Reference
- Specification: Snapshot Sessions Specification
- Specification Change: DRIVERS-2782 commit
- Test Specification: Session Tests README
- split from
-
DRIVERS-2782 Expose atClusterTime parameter in snapshot sessions
-
- Implementing
-