@@ -92,7 +92,7 @@ The components of this string are:
92
92
93
93
* - ``?options``
94
94
95
- - Connection specific options. See
95
+ - A query string that specifies connection specific options. See
96
96
:ref:`connections-connection-options` for a full description of
97
97
these options.
98
98
@@ -133,81 +133,93 @@ The components of this string are:
133
133
134
134
.. index:: connections; dns-seedlist
135
135
.. _connections-dns-seedlist:
136
-
137
-
136
+
137
+
138
138
DNS Seedlist Connection Format
139
139
------------------------------
140
140
141
141
.. versionadded:: 3.6
142
142
143
143
In addition to the standard connection format, MongoDB supports a
144
- DNS-constructed seedlist. Using DNS to construct the available servers
145
- list allows more flexibility of deployment and the ability to change the
146
- servers in rotation without reconfiguring clients.
144
+ :abbr:`DNS (Domain Name Service)`-constructed seed list. Using DNS to
145
+ construct the available servers list allows more flexibility of
146
+ deployment and the ability to change the servers in rotation without
147
+ reconfiguring clients.
147
148
148
149
In order to leverage the DNS seedlist, use a connection string prefix of
149
- ``mongodb+srv:`` in place of the ``mongodb:`` string above.
150
+ ``mongodb+srv:`` rather than the standard ``mongodb:``. The ``+srv``
151
+ indicates to the client that the hostname that follows corresponds to a
152
+ DNS SRV record. The driver or :binary:`~bin.mongo` shell will then
153
+ query the DNS for the record to determine which hosts are running the
154
+ :binary:`~bin.mongod` instances.
150
155
151
- The ``+srv`` indicates to the mongo client that the hostname that
152
- follows corresponds to a DNS SRV record. The client driver will then
153
- query the DNS for the record to determine the hosts that are running the
154
- mongod instances.
156
+ .. note::
155
157
156
- For example, to connect to a DNS-listed hostname:
158
+ Use of the ``+srv`` connection string modifier
159
+ automatically sets the ``ssl`` option to ``true`` for the connection.
160
+ You can override this behavior by explicitly setting the ``ssl``
161
+ option to ``false`` with ``ssl=false`` in the query string.
162
+
163
+ The following example shows a typical connection string for a DNS
164
+ seedlist connection string:
157
165
158
166
.. code-block:: none
159
167
160
- mongodb+srv://server.example.com/
168
+ mongodb+srv://server.example.com/
161
169
162
- A typical DNS configuration for the connection string above might look
163
- something like this:
170
+ The corresponding DNS configuration might resemble:
164
171
165
172
.. code-block:: none
166
173
167
174
Record TTL Class Priority Weight Port Target
168
175
_mongodb._tcp.server.example.com. 86400 IN SRV 0 5 27317 mongodb1.example.com.
169
176
_mongodb._tcp.server.example.com. 86400 IN SRV 0 5 27017 mongodb2.example.com.
170
177
171
- .. note::
172
- The hostnames returned in SRV records must share the same parent
173
- domain (in this example, ``example.com``) as the given hostname.
178
+ .. important::
179
+
180
+ The hostnames returned in SRV records must share the same parent
181
+ domain (in this example, ``example.com``) as the given hostname. If
182
+ the parent domains and hostname do not match, you will not be able to
183
+ connect.
174
184
175
- The DNS seedlist connection string can also provide options as a query
176
- string, with a trailing "/?" as in the standard connection string above.
177
- However, the ``+srv`` appended to the standard connection string signals
178
- the driver to query the DNS for options as a configured TXT record.
179
-
180
- Only two options are available for configuration via a TXT record:
181
- ``replicaSet`` and ``authSource``, and only one TXT record is allowed
182
- per server. If multiple TXT records appear in the DNS and/or if the TXT
185
+ Like the standard connection string, the DNS seedlist connection string
186
+ supports specifying options as a query string. With a DNS seedlist
187
+ connection string, you can *also* specify the following options via a
188
+ TXT record:
189
+
190
+ - ``replicaSet``,
191
+ - ``authSource``.
192
+
193
+ You may only specify one TXT record per :binary:`~bin.mongod` instance.
194
+ If multiple TXT records appear in the DNS and/or if the TXT
183
195
record contains an option other than ``replicaSet`` or ``authSource``,
184
- an error will be thrown by the driver .
196
+ the client will return an error .
185
197
186
- An example of a properly configured TXT record :
198
+ The TXT record for the ``server.example.com`` DNS entry would resemble :
187
199
188
200
.. code-block:: none
189
201
190
202
Record TTL Class Text
191
203
server.example.com. 86400 IN TXT "replicaSet=mySet&authSource=authDB"
192
204
193
- In this case, taking into account both the DNS SRV records and the
194
- options retrieved from the TXT records, the parsed string will look like :
205
+ Taken together, the DNS SRV records and the options specified in the TXT
206
+ record resolve to the following standard format connection string:
195
207
196
208
.. code-block:: none
197
209
198
210
mongodb://mongodb1.example.com:27317,mongodb2.example.com:27017/?replicaSet=mySet&authSource=authDB
199
211
200
- Options set in a TXT record can be overridden by passing in a query
201
- string with the URI . In the example below , the query string has provided
212
+ You can override the options specified in a TXT record by passing the option
213
+ in the query string . In the following example , the query string has provided
202
214
an override for the ``authSource`` option configured in the TXT record
203
215
of the DNS entry above.
204
216
205
217
.. code-block:: none
206
218
207
219
mongodb+srv://server.example.com/?connectTimeoutMS=300000&authSource=aDifferentAuthDB
208
220
209
- The rest of the option string will remain, and we can expect that the
210
- resulting URI would look like this (after parse).
221
+ Given the override for the ``authSource``, the equivalent connection
222
+ string in the standard format would be:
211
223
212
224
.. code-block:: none
213
225
@@ -217,10 +229,15 @@ resulting URI would look like this (after parse).
217
229
The ``mongodb+srv`` option will fail if there is no available DNS
218
230
with records that correspond to the hostname identified in the
219
231
connection string. In addition, use of the ``+srv`` connection string
220
- modifier sets the ``ssl`` option to ``true`` automatically for the
221
- connection. This can be overridden by explicitly setting the ``ssl``
222
- option to ``false`` with ``ssl=false`` in the query string.
232
+ modifier automatically sets the ``ssl`` option to ``true`` for the
233
+ connection. You can override this behavior by explicitly setting the
234
+ ``ssl`` option to ``false`` with ``ssl=false`` in the query string.
223
235
236
+ .. see::
237
+
238
+ :ref:`example-connect-mongo-using-srv` provides an example of
239
+ connecting the :binary:`~bin.mongo` shell to a replica set using
240
+ the DNS Seedlist Connection Format.
224
241
225
242
.. index:: connections; options
226
243
.. _connections-connection-options:
@@ -849,5 +866,3 @@ The following connects to a sharded cluster with three :binary:`~bin.mongos` ins
849
866
.. code-block:: none
850
867
851
868
mongodb://router1.example.com:27017,router2.example2.com:27017,router3.example3.com:27017/
852
-
853
-
0 commit comments