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

ReadPreference on client is not respected

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Critical - P2 Critical - P2
    • 0.2.0
    • Affects Version/s: None
    • 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)
      

       

            Assignee:
            kris.brandow@mongodb.com Kristofer Brandow (Inactive)
            Reporter:
            aaronszy Aaron Szymanski
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: