#Debugging mongo connection through mongo go driver

11 messages · Page 1 of 1 (latest)

tall dawn
#

Is there any reason why connecting to my atlas instance can be blocked by go
Am I missing out on something like firewall settings which are tied to the app
The same uri works with the node version of the app + in the prod deployment and I should add that it stopped working randomly for my local dev env of go. I have been told the error is due to network connectivity being blocked but not sure where to start debugging this
I am using the mongo go driver.

The error is "NoReplicaSetForPrimary" it is emitted after the timeout for all types of query.

It is strange since this happened completely randomly. I have the version of this app running on cloud and it works fine. I have connected using the same uri in multiple applications and it works perfectly.

err := godotenv.Load()
    if err != nil {
        log.Fatal("Error loading .env file")
    }

    serverAPIOptions := options.ServerAPI(options.ServerAPIVersion1)

    clientOptions := options.Client().
        ApplyURI(os.Getenv("MONGODB_URI")).
        SetServerAPIOptions(serverAPIOptions)
        //.SetDirect(true)

    ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
    defer cancel()

    conn, merr := mongo.Connect(ctx, clientOptions)

    if merr != nil {
        log.Fatal(merr)
    }
marble sinew
#

there is a problem with the cluster imo. try drop and recreate it.

tall dawn
#

Yeah I know but the same conn uri works everywhere else

#

So idk

marble sinew
#

the problem is with the cluster, its a cluster. everytime you connect, there no guarantee that you are connected to the same node.

#

or so i though. multiple stackoverflow threads has the same solution.

tall dawn
#

Drop and recreate?

tall dawn
#

Alright thanks

#

Will look and update here