ReadPreference on client is not respected

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Critical - P2
    • 0.2.0
    • Affects Version/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • 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:
              Kristofer Brandow (Inactive)
              Reporter:
              Aaron Szymanski
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: