@@ -131,6 +131,78 @@ The components of this string are:
131
131
132
132
mongodb://r1.example.net:27017,r2.example.net:27017/
133
133
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
+
134
206
.. index:: connections; options
135
207
.. _connections-connection-options:
136
208
0 commit comments