Skip to content

Allow configuration of ReadConcern for queries and aggregations #4277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sad3rasd opened this issue Jan 18, 2023 · 2 comments
Closed

Allow configuration of ReadConcern for queries and aggregations #4277

sad3rasd opened this issue Jan 18, 2023 · 2 comments
Assignees
Labels
type: enhancement A general enhancement

Comments

@sad3rasd
Copy link

Hi,
I would like to use find and aggregate query with readConcern level "snapshot" (and "atClusterTime") in order to get data at a specified point in time.

I can't find any way to implement this with spring data mongodb, am I miss something?
If not already available, how can be implemented using MongoTemplate? Also could this feature be added?

more info: https://www.mongodb.com/docs/manual/reference/read-concern-snapshot/

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 18, 2023
@mp911de mp911de added the type: enhancement A general enhancement label Jan 23, 2023
@mp911de mp911de self-assigned this Jan 23, 2023
@mp911de mp911de added status: pending-design-work Needs design work before any code can be developed and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 23, 2023
@mp911de mp911de changed the title Missing support for readConcern snapshot query Allow configuration of ReadPreference for queries and aggregations Jan 24, 2023
@mp911de
Copy link
Member

mp911de commented Jan 24, 2023

ReadPreferences can be set via:

  1. MongoTemplate for commands that operate on a collection
  2. Query meta flags via CursorOption.SECONDARY_READS

It would be neat if we could provide the ReadPreference through Query and AggregationOptions.

@mp911de mp911de removed the status: pending-design-work Needs design work before any code can be developed label Jan 24, 2023
@mp911de mp911de changed the title Allow configuration of ReadPreference for queries and aggregations Allow configuration of ReadConcern for queries and aggregations Feb 6, 2023
@mp911de
Copy link
Member

mp911de commented Feb 6, 2023

Please note that atClusterTime is a driver-internal attribute that is used with client sessions to track the latest cluster time. It is not intended to go back in time. See also the specification on snapshot reads:

https://github.com/mongodb/specifications/blob/master/source/sessions/snapshot-sessions.rst

For snapshot reads the driver MUST first obtain atClusterTime from the server response of a find/aggregate/distinct command, by specifying readConcern with snapshot level field, and store it as snapshotTime in the ClientSession object.

{
    find : <string>, // or other read command
    ... // the rest of the command parameters
    readConcern :
    {
        level : "snapshot"
    }
}

For subsequent reads in the same session, the driver MUST send the snapshotTime saved in the ClientSession as the value of the atClusterTime field of the readConcern with a snapshot level:

{
    find : <string>, // or other read command
    ... // the rest of the command parameters
    readConcern :
    {
        level : "snapshot",
        atClusterTime : <BsonTimestamp>
    }
}

The current documentation creates a slightly different impression of a wayback-machine.

Zxgg pushed a commit to Zxgg/spring-data-mongodb that referenced this issue Feb 7, 2023
Zxgg pushed a commit to Zxgg/spring-data-mongodb that referenced this issue Feb 7, 2023
@christophstrobl christophstrobl added this to the 4.1 M1 (2023.0.0) milestone Feb 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
4 participants