The mongo SRV connection string allow mongo clients to resolve the individual server names using DNS.

If you need to debug connection problems or simply are curious about the hosts used, you find them by making DNS queries using dig or even https://dns.google.com/

The Connection Format

mongodb+srv://USER:PASSWORD@CLUSTER.mongodb.net/DATABASENAME

The replica set name

Get the TXT (DNS) record using dig:

dig TXT CLUSTER.mongodb.net
; <<>> DiG 9.11.3-1ubuntu1.11-Ubuntu <<>> TXT CLUSTER.mongodb.net
 ;; global options: +cmd
 ;; Got answer:
 ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 5719
 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
 ;; OPT PSEUDOSECTION:
 ; EDNS: version: 0, flags:; udp: 65494
 ;; QUESTION SECTION:
 ;CLUSTER.mongodb.net.    IN  TXT
 ;; ANSWER SECTION:
 CLUSTER.mongodb.net. 60    IN  TXT "authSource=admin&replicaSet=REPLICASET_NAME

List of servers (and port number)

Get the SRV (DNS) record using dig:

dig srv _mongodb._tcp.CLUSTER.mongodb.net
; <<>> DiG 9.11.3-1ubuntu1.11-Ubuntu <<>> srv _mongodb._tcp.CLUSTER.mongodb.net
 ;; global options: +cmd
 ;; Got answer:
 ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 9387
 ;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1
 ;; OPT PSEUDOSECTION:
 ; EDNS: version: 0, flags:; udp: 65494
 ;; QUESTION SECTION:
 ;_mongodb._tcp.CLUSTER.mongodb.net. IN SRV
 ;; ANSWER SECTION:
 _mongodb._tcp.CLUSTER.mongodb.net. 60 IN    SRV 0 0 27017 SERVER-01.mongodb.net.
 _mongodb._tcp.CLUSTER.mongodb.net. 60 IN    SRV 0 0 27017 SERVER-02.mongodb.net.
 _mongodb._tcp.CLUSTER.mongodb.net. 60 IN    SRV 0 0 27017 SERVER-00.mongodb.net.

IP Address

Now you can resolve the IP address for each node:

dig SERVER-01.mongodb.net

References

Categories: TL;DR

0 Comments

Leave a Reply

Avatar placeholder