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

ListCollections failed

    • Type: Icon: Bug Bug
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 1.8.3
    • Component/s: None

      Summary

      MongoDB server version and topology: 4.4 / master+ a slave node replica set

      driver version: master

       

      How to Reproduce

      1.  Down the master node.Now only a slave node is on lived.
      2. use uri mongodb://[username]:[password]@master_ip,slave_ip/db_name
      3. Set the client option readPreference to primaryPreferred
      4. Then NewClient and ListCollections.

      The code like:

      package main
      
      import (
         "context"
         "go.mongodb.org/mongo-driver/bson"
         "go.mongodb.org/mongo-driver/mongo"
         "go.mongodb.org/mongo-driver/mongo/options"
         "go.mongodb.org/mongo-driver/mongo/readpref"
         "log"
      )
      
      func main() {
         opts := options.Client().SetReadPreference(readpref.PrimaryPreferred())
         client, err := mongo.NewClient(options.Client().ApplyURI(""), opts)
         if err != nil {
            log.Fatal(err)
         }
         
         if err := client.Connect(context.Background()); err != nil {
            log.Fatal(err)
         }
         
         _, err = client.Database("dbName").ListCollections(context.Background(), bson.D{})
         if err != nil {
            log.Fatal(err)
         }
      }

      It will return error like:

      server selection error: server selection timeout, current topology: {Type: ReplicaSetNoPrimary}

      By reading source code of mongo-go-driver,I think the problem be here:

       

            Assignee:
            benji.rewis@mongodb.com Benji Rewis (Inactive)
            Reporter:
            mrliuxiansen8023@gmail.com du liu
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: