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

mongo.Connect is always succeeding even the db is not up

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 0.0.7
    • Component/s: Connections, Error Handling
    • None

       

      Gopkg.lock
      
      [[projects]]
        name = "github.com/mongodb/mongo-go-driver"
        packages = [
          "bson",
          "bson/builder",
          "bson/decimal",
          "bson/elements",
          "bson/internal/jsonparser",
          "bson/objectid",
          "bson/parser",
          "bson/parser/ast",
          "core/address",
          "core/auth",
          "core/auth/internal/gssapi",
          "core/command",
          "core/connection",
          "core/connstring",
          "core/description",
          "core/dispatch",
          "core/option",
          "core/readconcern",
          "core/readpref",
          "core/result",
          "core/tag",
          "core/topology",
          "core/version",
          "core/wiremessage",
          "core/writeconcern",
          "internal",
          "mongo"
        ]
        revision = "bb548a5e4d4cabb086e6425b113b07270e40bbb8"
        version = "v0.0.7"
      

       

      My golang connection code 

      MongoConnect : Mongo Connection clientfunc MongoConnect() (*mongo.Client, error) {    
        MongoConnURL := "mongodb://127.0.0.1:27017"
        ctx := context.Background()    
        client, err := mongo.Connect(ctx, MongoConnURL, nil)
        fmt.Println("connection error is ", err)    
        if err != nil {
          print("Error in creating connection with context", err)        
          return nil, err    
        }
        fmt.Println("Monogo connection success ... \n", client)
        return client, nil
      }
      
      

      Output while mongodb is local is up

      connection error is <nil>
      Monogo connection success ... &{[] 0xc4201c39e0 {mongodb://127.0.0.1:27017 map[] admin 0 false 0 false 0 false [127.0.0.1:27017] false false 0 false 0 false 0 0 false 0 false false [] 0 false 0 false 0 false false false false <nil> false false false false 0 false 0 false false map[] map[]} 1500000 0 0x1ce6d40 <nil> <nil>} 
      

       

      while mongodb in local is down

      connection error is  <nil>
      Monogo connection success ...
       &{[] 0xc420354090 {mongodb://127.0.0.1:27017   map[] admin 0 false 0 false  0 false [127.0.0.1:27017] false false 0 false 0 false 0 0 false 0 false  false   [] 0 false  0 false 0 false false false  false <nil> false false false  false  0 false  0 false false map[] map[]} 15000000 0x1ce6d40 <nil> <nil>}
      

            Assignee:
            kris.brandow@mongodb.com Kristofer Brandow (Inactive)
            Reporter:
            jeyanthi jeyanthi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: