server selection timeout error when connecting to replica set

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Done
    • Priority: Major - P3
    • None
    • Affects Version/s: 0.0.18
    • Component/s: Connections
    • None
    • Environment:
      2 mongodb with docker (replica set configured successfully, shell connection works fine)
      macOS 10.14.1
      go 1.11.2 with go module
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      ctx := context.Background()
      
      clientOptions := &options.ClientOptions{}
      clientOptions.SetHosts([]string\{"mongodb://localhost:27017", "mongodb://localhost:27018"})
      clientOptions.SetReadPreference(readpref.Primary())
      clientOptions.SetServerSelectionTimeout(time.Duration(2*time.Second))
      
      client, err := mongo.NewClientWithOptions("mongodb://localhost:27017,localhost:27018", clientOptions)
      if err != nil {
       panic(err)
      }
      
      err = client.Connect(ctx)
      if err != nil {
       panic(err)
      }
      
      dbs, err := client.ListDatabaseNames(ctx, bson.D{})
      if err != nil {
       panic(err)
      }
      
      fmt.Println(dbs)
      

      but result is: panic: server selection timeout
      I also added replicaSet=rs0 option but result was same.
      Does this driver not yet support replica set?

            Assignee:
            Unassigned
            Reporter:
            성욱 조
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: