-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 0.0.18
-
Component/s: Server Selection
Specifying connect=direct to a secondary replica set still requires slaveOk to be set. For example:
mongoURI := "mongodb://SECONDARY:PORT/?connect=direct" client, err := mongo.NewClient(mongoURI) if err != nil { log.Fatal(err) } client.Connect(context.TODO()) database := client.Database("dbName") collection := database.Collection("collName") cursor := collection.FindOne(context.TODO(), bson.D{}) if err != nil { log.Fatal(err) }
This will result in :
2018/11/19 08:53:14 (NotMasterNoSlaveOk) not master and slaveOk=false
exit status 1
However, adding readPreference secondary the connection URI works to connect directly to a secondary member.
mongoURI := "mongodb://SECONDARY:PORT/?connect=direct&readPreference=secondary"
Worth mentioning that specifying the secondary itself, will do the correct server discovery and will send the query to Primary:
mongoURI := "mongodb://SECONDARY:PORT/
SDAM reference : Server Selection: Topology Type Single