Original post

Hi,

I’m unable to connect MongoDB with SRV protocol, please help me connect.

MyCode:

package main

import (
“context”
“fmt”
“log”
“time”

".mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"go.mongodb.org/mongo-driver/mongo/readpref"

)

func main() {
domain := “mongodb+srv://USERNAME:PASSWORD@cluster1.gdbmd.mongodb.net/my_docker_db?retryWrites=true&w=majority”
fmt.Println(domain)
client, err := mongo.NewClient(options.Client().ApplyURI(domain))
if err != nil {
log.Fatal(err)
}
fmt.Println(“No Error”)
ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
err = client.Connect(ctx)
if err != nil {
log.Fatal(err)
}
defer client.Disconnect(ctx)
err = client.Ping(ctx, readpref.Primary())
if err != nil {
log.Fatal(err)
}
databases, err := client.ListDatabaseNames(ctx, bson.M{})
if err != nil {
log.Fatal(err)
}
fmt.Println(databases)
}

Error:
error parsing uri: lookup cluster1.gdbmd.mongodb.net on 127.0.0.53:53: cannot unmarshal DNS message

Thanks,
Prakash.N