0

I'm using the go connector for mongo db and I'm trying to connect to my atlas database:

func NewMongoClient() (*mongo.Client, error) {
    pw := os.Getenv("mongopw")
    // mongodb://tesohh:%s@cluster0/<dbname>?ssl=true&replicaSet=<replica setname>&authSource=admin'
    //mongodb://tesohh:%s@cluster0.ojujhay.mongodb.net/?ssl=true&authSource=admin
    uri := fmt.Sprintf("mongodb+srv://tesohh:%s@cluster0.ojujhay.mongodb.net/?retryWrites=true&w=majority", pw)
    client, err := mongo.Connect(context.Background(), options.Client().ApplyURI(uri))
    if err != nil {
        return nil, err
    }
    return client, err
}

but I get this: panic: error parsing uri: see https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#hdr-Potential_DNS_Issues: lookup cluster0.ojujhay.mongodb.net on 172.20.10.1:53: cannot unmarshal DNS message.

What does it mean to "avoid the +srv scheme"? By the way changing my dns settings is not an option.

Tesohh
  • 111
  • 1
  • 6
  • `"avoid the +srv scheme"` means don't use the `mongodb+srv` scheme to lookup srv records, because your dns server is returning invalid srv records. – JimB Aug 14 '23 at 13:39

0 Answers0