Skip to content

Commit 36fc4d5

Browse files
p-mongop
andauthored
RUBY-2293 Document retrieving auth source from TXT records with SRV URIs (#2043)
Co-authored-by: Oleg Pudeyev <[email protected]>
1 parent 3a7f641 commit 36fc4d5

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

source/tutorials/ruby-driver-authentication.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,23 @@ if no database is specified, the ``$external`` database is used as the
8989
auth source. For the ``AWS``, ``GSSAPI`` and ``MONGODB_X509`` mechanisms, the
9090
auth source is always ``$external``.
9191

92+
When a client is constructed using an SRV URI, the driver will look for URI
93+
options in a TXT DNS record that corresponds to the SRV record. Thus, for
94+
example, MongoDB Atlas generally uses the ``admin`` database as its auth
95+
source, but this is not specified in SRV URIs because the database is given
96+
as a URI option on the TXT records.
97+
98+
Note that when using SRV URIs, the SRV query and the TXT query are performed
99+
separately. On systems where DNS resolution is not 100% reliable, the
100+
failure to look up TXT records can cause authentication errors, as the driver
101+
may end up using an incorrect auth source. If reliable DNS resolution cannot
102+
be guaranteed, the auth source can be specified explicitly in SRV URIs as
103+
a URI option:
104+
105+
.. code-block:: ruby
106+
107+
Mongo::Client.new("mongodb+srv://username:[email protected]/test?w=majority&authSource=admin")
108+
92109
.. note::
93110

94111
When changing the database using the ``with`` method, the auth source is

0 commit comments

Comments
 (0)