-
Type: Bug
-
Resolution: Fixed
-
Priority: Critical - P2
-
Affects Version/s: None
-
Component/s: Options & Configuration
-
None
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)