[GODRIVER-701] ReadPreference on client is not respected Created: 13/Dec/18  Updated: 28/Oct/23  Resolved: 19/Dec/18

Status: Closed
Project: Go Driver
Component/s: Options & Configuration
Affects Version/s: None
Fix Version/s: 0.2.0

Type: Bug Priority: Critical - P2
Reporter: Aaron Szymanski Assignee: Kristofer Brandow (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

ReadPreferences is only respected when included in the connection string. When configured programmatically, it's ignored.

// Read preference is ignored
// Reads when no primary is present yields "(NotMasterNoSlaveOk) not master and slaveOk=false"
mongoConnString := "mongodb://mongo1,mongo2,mongo3/?replicaSet=rs0"
client, err := mongo.NewClientWithOptions(mongoConnString,
  options.Client().SetReadPreference(readpref.PrimaryPreferred()), 
)

 // Read preference is respected
mongoConnString := "mongodb://mongo1,mongo2,mongo3/?replicaSet=rs0&readPreference=primaryPreferred"
client, err := mongo.NewClientWithOptions(mongoConnString)

 



 Comments   
Comment by Githook User [ 19/Dec/18 ]

Author:

{'username': 'skriptble', 'email': 'kris@mongodb.com', 'name': 'Kris Brandow'}

Message: Ensure readpref and concerns can be set on client

GODRIVER-701

Change-Id: Idc5ccf42ac398c1f883c346f2d6744a45a661573
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/eac374e46b4e4762ee6ebf574d1f1e73e312d552

Comment by Kristofer Brandow (Inactive) [ 18/Dec/18 ]

Code Review: https://review.gerrithub.io/c/mongodb/mongo-go-driver/+/437718/.

Comment by Aaron Szymanski [ 14/Dec/18 ]

Actually it looks like it is ignoring all options not in the connection string. I just tried setting:

options.Client().SetWriteConcern(writeconcern.New(
	writeconcern.WMajority()
)),

and it is also ignored.

Comment by Aaron Szymanski [ 13/Dec/18 ]

Forgot to set my version on this ticket... should be v0.1.0.

Generated at Thu Feb 08 08:34:46 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.