-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
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?
- related to
-
GODRIVER-2499 Use a nested struct for default transaction options
- Closed