Skip to content

Commit 5e3fdec

Browse files
DOCSP-45614-connection-string-examples (#726)
* DOCSP-45614-connection-string-examples * reviewer changes * reviewer updates * address feedback
1 parent f8d6bf8 commit 5e3fdec

File tree

1 file changed

+107
-2
lines changed

1 file changed

+107
-2
lines changed

source/connect.txt

Lines changed: 107 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,32 @@ Use Advanced Connection Options
101101

102102
.. include:: /includes/intro-advanced-connection-options.rst
103103

104-
For details, see :ref:`advanced-connection-options`.
104+
For details on how to specify connection options using Compass,
105+
see :ref:`advanced-connection-options`.
105106

106107
Connect to Compass from the Command Line
107108
----------------------------------------
108109

109110
.. include:: /includes/intro-command-line-connection.rst
110111

111-
For details, see :ref:`comp-command-line-connect`.
112+
To connect to Compass using the command line, you can include your connection
113+
options directly in your connection string or as command line arguments.
114+
115+
To specify connection options in your connection string, use the following format:
116+
117+
.. code-block::
118+
119+
mongodb-compass 'mongodb://username:password@hostname:port/database?ssl=true&replicaSet=myReplicaSet'
120+
121+
For more connection string options, see :ref:`connections-connection-options`.
122+
123+
To specify connection options as command line arguments, use the following format:
124+
125+
.. code-block::
126+
127+
<path/to/compass/executable> <connection string> --username <username> --password <password>
128+
129+
For more command line argument connection options, see :ref:`comp-command-line-connect`.
112130

113131
.. seealso::
114132

@@ -123,3 +141,90 @@ For details, see :ref:`comp-command-line-connect`.
123141
Favorite Connections </connect/favorite-connections>
124142
Required Access </connect/required-access>
125143
Disconnect </connect/disconnect>
144+
145+
Connection String Examples
146+
--------------------------
147+
148+
The following examples highlight some advanced connection string options.
149+
For information on all connection string options, see :ref:`connections-connection-options`.
150+
151+
TLS Options
152+
~~~~~~~~~~~
153+
154+
The following connection string enables TLS using the ``tls`` URI option.
155+
``tlsCertificateKeyFile`` specifies the path to the client certificate and
156+
private key. Specifying the ``tlsCertificateKeyFile`` in your connection string
157+
is optional, unless the server requires client certificates, or if
158+
you are using X.509 authentication.
159+
160+
.. code-block::
161+
162+
mongodb://myDatabaseUser:D1fficultP%[email protected]/?directConnection=true&tls=true&tlsCAFile=path/to/rootCA.crt&tlsCertificateKeyFile=path/to/server_certificate.pem
163+
164+
To enable SSL, use the equivalent ``ssl=true`` option in place of ``tls=true``.
165+
166+
X.509 Authentication
167+
````````````````````
168+
169+
The following example demonstrates how to specify X.509 authentication in your connection string
170+
using the :urioption:`authMechanism` connection string option:
171+
172+
.. code-block::
173+
174+
mongodb://myDatabaseUser:D1fficultP%[email protected]/?authMechanism=MONGODB-X509&tls=true&tlsCertificateKeyFile=/path/to/client_certificate.pem
175+
176+
LDAP
177+
~~~~
178+
179+
The following example specifies LDAP authentication. It sets :urioption:`authMechanism` to ``plain``
180+
to specify the use of the LDAP authentication mechanism and sets ``authSource`` to ``$external``
181+
to indicate that the authentication database is ``$external``.
182+
183+
.. code-block::
184+
185+
mongodb://myDatabaseUser:D1fficultP%[email protected]/?authMechanism=PLAIN&authSource=$external
186+
187+
Kerberos
188+
~~~~~~~~
189+
190+
The following example specifies Kerberos authentication. It sets :urioption:`authMechanism` to
191+
``GSSAPI`` to use the Kerberos authentication mechanism and sets ``authSource`` to ``$external``
192+
to indicate that the authentication database is ``$external``.
193+
194+
.. code-block::
195+
196+
mongodb://[email protected]/?authMechanism=GSSAPI&authSource=$external
197+
198+
Read/Write Preferences
199+
~~~~~~~~~~~~~~~~~~~~~~
200+
201+
To enable read/write preferences in your connection string, you can use the
202+
``readPreference`` option for read preferences and the ``w`` option for write concerns.
203+
204+
The following connection string sets both read and write preferences.
205+
``readPreference=secondary`` specifies that read operations should be directed to secondary
206+
members of the replica set and ``w=majority`` ensures that write operations are
207+
acknowledged by the majority of the replica set members.
208+
209+
.. code-block::
210+
211+
mongodb://myDatabaseUser:D1fficultP%[email protected]/database?readPreference=secondary&w=majority
212+
213+
Analytic Nodes
214+
~~~~~~~~~~~~~~
215+
216+
To specify an ``analytics`` node type in your connection string:
217+
218+
- Set your ``readPreference`` to ``secondary`` to specify that the read operations
219+
should be directed to secondary nodes.
220+
- Set ``readPreferenceTags`` to ``nodeType:ANALYTICS`` to ensure that the read operations
221+
are directed specifically to the analytic nodes.
222+
223+
The following connection string demonstrates how to specify an ``analytics`` node type in your
224+
connection string:
225+
226+
.. code-block::
227+
228+
mongodb+srv://myDatabaseUser:D1fficultP%[email protected]/myDatabase?readPreference=secondary&readPreferenceTags=nodeType:ANALYTICS
229+
230+
For more information on using analytics nodes to isolate workloads, see :ref:`replica-set-tags`.

0 commit comments

Comments
 (0)