Can't connect to Mongo Cloud mongodb Database in Golang on Ubuntu

后端 未结 3 1164
庸人自扰
庸人自扰 2020-12-19 20:35

I have this Go Code to connect to my Mongo Cloud Database:

func connectToDataBase() {
    ctx, cancel := context.WithTimeout(context.Background(), 20*time.Se         


        
3条回答
  •  旧时难觅i
    2020-12-19 21:24

    cannot unmarshal DNS message

    This is not quite related to MongoDB Go driver.

    There is a patch in Go version 1.11.x #10622 net: target domain names in SRV records should not be compressed that tighten the way SRV records are read to follow RFC-2782.

    If an authoritative DNS server (non-compliantly) sends an SRV records using domain name compression, the net.lookupSRV() will throw an error with cannot unmarshal DNS message (net/lookup_unix.go#L130). For example, the embedded Docker DNS maybe doing the server name compression.

    The workarounds for Go v1.11 are:

    • Use the non-SRV MongoDB URI
    • Update the content of /etc/resolv.conf by replacing the nameserver to use a compliant and/or public DNS server i.e. 1.1.1.1 or 8.8.8.8

    See also GODRIVER-829

提交回复
热议问题