Mongodb Atlas connect with docker app golang

My whole application already dockerize & I want to add mogodb database in our project. here is following code

serverAPIOption := options.ServerAPI(options.ServerAPIVersion1)
clientOptions := options.Client().ApplyURI(“mongodb+srv://enigma:@cluster0.ckk7d.mongodb.net/enigma?retryWrites=true&w=majority”).
SetServerAPIOptions(serverAPIOption)

client, err := mongo.NewClient(clientOptions)
if err != nil {
log.Fatalln(“Error create client object :”, err)
return &mongo.Client{}
}

docker run --rm --hostname=wizdwarfs --net=host -p 127.0.0.1:5000:5000 -v app:/app/app_data -it v0b

2022/05/12 12:16:11 Error create client object : error parsing uri: lookup cluster0.ckk7d.mongodb.net on 127.0.0.53:53: cannot unmarshal DNS message, Please help. --net=host allow you to connect with internet; either this cause by docker or some technical issue

Hi @Ali_Hassan1 - Welcome to the community!

The above error message could possibly be caused by to what is detailed on https://jira.mongodb.org/browse/GODRIVER-829. More specifically, I would refer to the following comment on March 15 which provides more information on the possible causes and a solution / workaround.

If you still require additional assistance, please:

  1. Replace the DNS Seed List Connection Format (beginning with "mongodb+srv://") with the Standard Connection String Format (beginning with "mongodb://") and advise if the error message is still present. Please provide the full error message once this is attempted.
  2. Advise the MongoDB Go driver version
  3. Advise the Go language version
  4. Attempt to connect from outside the docker environment using the same connection string and advise if you are able to connect.

Regards,
Jason

1 Like

Thanks … Some day I will try but currently I’m very busy in different project

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.