"cannot unmarshal DNS message" for SRV lookup
this gists won't go over DNS setup part for +srv to work
When you google this error, you will get something few results, one of which is this. If you are not using Docker that one will actually not help you, but will definitly give you perspective on a problem.
This error is pretty straight forward and a slippery to fix. Let's see whats going on. So offical documentation
The hostnames returned in SRV records must share the same parent domain (in this example, example.com) as the given hostname. If the parent domains and hostname do not match, you will not be able to connect. This doc part is actually explaing how to setup domain. In my
+srv
was not a priority so I skipped it.
To go around this error, you have to use old MongoDB formating string
mongodb://
. Only problem is how to get valid string generated for your cluster.
Fix for this in MongoDB Atlas:
- Connect
- Connect your application
- Choose driver 'Node 2.2.12 or earlier'
Copy generated code to your uri place (be sure to replace with your database password, and with your database name)
client, err := mongo.NewClient(options.Client().ApplyURI("mongodb://"))
if err != nil {
log.Fatal(err)
}
ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
err = client.Connect(ctx)
if err != nil {
log.Fatal(err)
}