Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-641

Connect direct to a replica set member also requires ReadPreference to be set

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 0.2.0
    • Affects Version/s: 0.0.18
    • Component/s: Server Selection
    • Labels:

      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

            Assignee:
            devin.hilly@mongodb.com Devin Hilly (Inactive)
            Reporter:
            wan.bachtiar@mongodb.com Wan Bachtiar
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: