[GODRIVER-641] Connect direct to a replica set member also requires ReadPreference to be set Created: 18/Nov/18  Updated: 28/Oct/23  Resolved: 18/Dec/18

Status: Closed
Project: Go Driver
Component/s: Server Selection
Affects Version/s: 0.0.18
Fix Version/s: 0.2.0

Type: Bug Priority: Major - P3
Reporter: Wan Bachtiar Assignee: Devin Hilly (Inactive)
Resolution: Fixed Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

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



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

Author:

{'username': 'dmhilly', 'email': 'devin.hilly@mongodb.com', 'name': 'Devin Hilly'}

Message: Remove readPref requirement with connect=direct

GODRIVER-641

Change-Id: I7d65dabdeb972c814e0e107dee8f871592618591
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/5277acc08076dd9c006b8192af290d97591a31b4

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