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

Go couldn't connect mongodb 2.4 version

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Won't Do
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None

    Description

      I couln't connect mongodb with golang.

      telnet mongoHost 27017 it is okey

      ping mongoHost it is okey

      MongoHost is my private host not docker

      Mongodb version : 2.4.3

      MongoDriver: 1.3.2

      Go version: go version go1.14.1 darwin/amd64

      Operation System: Mac

      Here is my connection code

       

       
      clientOptions := &options.ClientOptions{}
      clientOptions.SetServerSelectionTimeout(4 * time.Second)
      clientOptions.SetDirect(true)
      clientOptions.SetAppName("tests")
      clientOptions.SetHosts([]string{"mongoHost:27017"})
      clientOptions.SetReadPreference(readpref.Secondary())
      client, err := mongo.NewClient(clientOptions)
      if err != nil {
          log.Fatal(err)
      }
      ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
      err = client.Connect(ctx)
      if err != nil {
          log.Fatal(err)
      } 

       

      I changed timeout but It doesn't changed connection every time I got this error:

      2020/04/12 14:06:19 server selection error: server selection timeout, current topology: { Type: Unknown, Servers: [{ Addr: mongoHost:27017, Type: Standalone, State: Connected, Average RTT: 13849652 }, ] }
       

      Attachments

        Activity

          People

            Unassigned Unassigned
            eroll.yapici@gmail.com erol yap?c?
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: