Skip to content

Commit e0f974c

Browse files
skerschbkay-kim
authored andcommitted
DOCS-10980 adding DNS seedlist
1 parent b5fb25e commit e0f974c

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

source/includes/options-mongo.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ description: |
7373
the CN or SAN of the {{instance}}'s ``--sslPEMKeyFile`` certificate.
7474
If the hostname does not match the CN/SAN, {{program}} will fail to
7575
connect.
76+
77+
For DNS seedlist connections, specify the connection protocol as
78+
``mongodb+srv:", followed by the DNS SRV hostname record and any
79+
options for overriding DNS TXT configured options. For example:
80+
81+
.. code-block:: none
82+
83+
mongodb+srv://server.mongodb.com/?connectionTimeout=3000ms
84+
85+
7686
optional: true
7787
replacement:
7888
instance: ":program:`mongod` or :program:`mongos`"

source/reference/connection-string.txt

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,78 @@ The components of this string are:
131131

132132
mongodb://r1.example.net:27017,r2.example.net:27017/
133133

134+
.. index:: connections; dns-seedlist
135+
.. _connections-dns-seedlist:
136+
137+
138+
DNS Seedlist Connection Format
139+
------------------------------
140+
141+
In addition to the standard connection format, MongoDB supports a DNS-constructed
142+
seedlist. Using the DNS to construct the available servers list allows more flexibility
143+
of deployment and the ability to change the servers in rotation without reconfiguring
144+
clients.
145+
146+
In order to leverage the DNS seedlist, use a connection string prefix of ``mongodb+srv:``
147+
in place of the ``mongodb:`` string above.
148+
149+
The ``+srv`` indicates to the mongo client that the hostname that follows corresponds to a
150+
DNS SRV record. The client driver will then query the DNS for the record to determine the hosts that
151+
are running the mongod instances.
152+
153+
For example, to connect to a DNS listed hostname:
154+
155+
.. code-block:: none
156+
157+
mongodb+srv://server.mongodb.com/
158+
159+
A typical DNS configuration for the connection string above might look something
160+
like this:
161+
162+
.. code-block:: none
163+
164+
Record TTL Class Priority Weight Port Target
165+
_mongodb._tcp.server.mongodb.com. 86400 IN SRV 0 5 27317 mongodb1.mongodb.com.
166+
_mongodb._tcp.server.mongodb.com. 86400 IN SRV 0 5 27017 mongodb2.mongodb.com.
167+
168+
The DNS seedlist connection string can also provide options with a trailing "/?" as in
169+
the standard connection string above. However, the ``+srv`` string in the connection URI will
170+
signal to the driver to query the DNS for options as configured TXT records. For example:
171+
172+
.. code-block:: none
173+
174+
Record TTL Class Text
175+
server.mongodb.com. 86400 IN TXT "ssl=true&connectTimeoutMS=250000"
176+
server.mongodb.com. 86400 IN TXT "readPreference=secondaryPreferred&readPreferenceTags=dc:ny,rack:1"
177+
178+
In this case, taking into account both
179+
the DNS SRV records and the options retrieved from the TXT records, the parsed string will look like:
180+
181+
.. code-block:: none
182+
183+
mongodb://mongodb1.mongodb.com:27317,mongodb2.mongodb.com:27107/?ssl=true&
184+
connectTimeoutMS=250000&readPreference=secondaryPreferred&readPreferenceTags=dc:ny,rack:1
185+
186+
The TXT records can be overridden by passing in a query string with the uri. In the example below,
187+
the only option that would be overridden in the text record would be the ``connectTimeoutMS``.
188+
189+
.. code-block:: none
190+
191+
mongodb+srv://server.mongodb.com/?connectTimeoutMS=300000
192+
193+
The rest of the option string will remain, and we can expect that the resulting uri
194+
would look like this (after parse).
195+
196+
.. code-block:: none
197+
198+
mongodb://mongodb1.mongodb.com:27317,mongodb2.mongodb.com:27107/?ssl=true&connectTimeoutMS=300000&read
199+
Preference=secondaryPreferred&readPreferenceTags=dc:ny,rack:1
200+
201+
.. note::
202+
The ``mongodb+srv`` option will fail if there is no available DNS with records which correspond to the
203+
hostname identified in the connect string.
204+
205+
134206
.. index:: connections; options
135207
.. _connections-connection-options:
136208

0 commit comments

Comments
 (0)