Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-1703

Change Session examples to use transactions

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.4.1
    • Affects Version/s: 1.3.5
    • Component/s: Documentation
    • None
    • Environment:
      go 1.14 on mac os x

      Updated Description

      https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo@v1.3.5?tab=doc#example-Client.UseSessionWithOptions uses the DefaultReadConcern option, which only applies to transactions started within a session, but does not start a transaction. This is confusing, so we should change the example to start a transaction. We should also verify that other sessions-related examples don't do the same thing.

       

      Previous Description 

      Using a session with readpref=Secondary results in queries against the primary.

      Please see the attached test case that demonstrates the issue.

      My setup:

      • Local Replica Set called "ci" with two nodes: port 27017 is the primary, 27016 is the secondary
      • RS config sets the secondary with priority=0 so it doesn't become primary
      • I use toxiproxy to artificially add latency from primary to secondary. This isn't necessary, but makes the test more reliably reproducible.

      Debugging FindOne() it seems like the read preference setting for the session is ignored if not inside a transaction. Setting the read preference on the Collection makes the test pass.

      I'm roughly following the example from https://godoc.org/go.mongodb.org/mongo-driver/mongo#Client.UseSession . Am I using the API incorrectly?

            Assignee:
            divjot.arora@mongodb.com Divjot Arora (Inactive)
            Reporter:
            dv@glyphy.com D V
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: