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

ReadPreference on client is not respected

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Critical - P2 Critical - P2
    • 0.2.0
    • None
    • None

    Description

      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)
      

       

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: