@@ -47,46 +47,45 @@ usage limits, such as max connections, apply to individual
47
47
48
48
.. _connection-uri:
49
49
50
- Connection String
51
- -----------------
50
+ Connection URI
51
+ --------------
52
52
53
- The **connection string** (also known as a **connection uri**) provides
54
- instructions on how to connect to a MongoDB deployment. The driver
55
- URL interprets the connection string to determine where and how
56
- it should connect to MongoDB as well as how to behave while
57
- connected. The following example shows each part of the connection URI:
53
+ The **connection URI** provides a set of instructions that the driver uses to
54
+ connect to a MongoDB deployment. It instructs the driver on how it should
55
+ connect to MongoDB and how it should behave while connected. The following
56
+ example explains each part of a sample connection URI:
58
57
59
- .. figure:: /includes/figures/connection_string_parts .png
58
+ .. figure:: /includes/figures/connection_uri_parts .png
60
59
:alt: Connection String parts figure
61
60
62
- In this example, for the protocol, we use ``mongodb+srv`` which specifies the
63
- :manual:`DNS Seedlist Connection Format </reference/connection-string/#std-label-connections-dns-seedlist>`.
64
- This indicates that the hostname following it corresponds to the DNS SRV record of your
65
- MongoDB instance or deployment. If your instance or deployment does not have a
66
- DNS SRV record, use ``mongodb`` to specify the :manual:`Standard Connection
67
- Format </reference/connection-string/#standard-connection-string-format>` .
61
+ In this example, we use the :manual:`Standard Connection String Format
62
+ </reference/connection-string/#std-label-connections-standard-connection-string-format>`,
63
+ ``mongodb`` for the protocol. You can also use the :manual:` DNS Seed
64
+ List Connection Format </reference/connection-string/#dns-seed-list-connection-format>`,
65
+ ``mongodb+srv``, if you want more flexibility of deployment and the
66
+ ability to change the servers in rotation without reconfiguring clients .
68
67
69
68
.. note::
70
69
71
- If your deployment is on MongoDB Atlas, follow the
70
+ If your deployment is on MongoDB Atlas, see the
72
71
:atlas:`Atlas driver connection guide </driver-connection?jmp=docs_driver_java>`
73
- to retrieve your connection string.
72
+ and select Java from the language dropdown to retrieve your connection string.
74
73
75
- The next part of the connection string contains your username and password
76
- if you are using password-based authentication. Replace the value of ``user``
77
- with your username and ``pass`` with your password. If you are using an
78
- authentication mechanism that does not require a username and password, omit
79
- this part of the connection URI.
74
+ The next part of the connection URI contains your credentials if you are
75
+ using a password-based authentication mechanism . Replace the value of ``user``
76
+ with your username and ``pass`` with your password. If your
77
+ authentication mechanism does not require credentials, omit this part of
78
+ the connection URI.
80
79
81
- The next part of the connection string specifies the hostname or IP address and
82
- port of your MongoDB instance. In the following example, we use ``sample-hostname``
83
- as the hostname and ``27017`` as the port. Replace these values to point to
84
- your MongoDB instance.
80
+ The next part of the connection URI specifies the hostname or IP
81
+ address, followed by the port of your MongoDB instance. In the example,
82
+ we use ``sample.host`` as the hostname and ``27017`` as the port.
83
+ Replace these values to refer to your MongoDB instance.
85
84
86
- The last part of the connection string contains connection and authentication
87
- options as parameters. In the following example, we set two connection options:
88
- ``retryWrites=true`` and `` w=majority``. For more information on connection
89
- options, skip to the :ref:`connection options <connection -options> ` section.
85
+ The last part of the connection URI contains connection options as parameters. In the
86
+ example, we set two connection options: ``maxPoolSize=20`` and
87
+ ``w=majority``. For more information on connection options, skip to the
88
+ :ref:`connection-options` section of this guide .
90
89
91
90
.. _connect-atlas-java-driver:
92
91
@@ -95,6 +94,7 @@ connect to MongoDB.
95
94
96
95
.. literalinclude:: /includes/fundamentals/code-snippets/srv.java
97
96
:language: java
97
+ :emphasize-lines: 17
98
98
99
99
.. _java-other-ways-to-connect:
100
100
@@ -159,7 +159,7 @@ Select the tab corresponding to the code snippet you would like to see:
159
159
160
160
.. code-block:: java
161
161
162
- ConnectionString connectionString = new ConnectionString("mongodb://host1:27017,host2:27017,host3:27017");
162
+ ConnectionString connectionString = new ConnectionString("mongodb://host1:27017,host2:27017,host3:27017/ ");
163
163
MongoClient mongoClient = MongoClients.create(connectionString);
164
164
165
165
.. tab:: MongoClientSettings
@@ -230,14 +230,14 @@ using a method in the ``MongoClientSettings.Builder`` class.
230
230
:tabid: connectionstring
231
231
232
232
To enable compression with a `ConnectionString
233
- <{+api+}/apidocs/mongodb-driver-sync /com/mongodb/ConnectionString.html>`__, use the parameter ``compressors``
233
+ <{+api+}/apidocs/mongodb-driver-core /com/mongodb/ConnectionString.html>`__, use the parameter ``compressors``
234
234
in the connection string passed to
235
235
``MongoClients.create()``. You can specify one or more compression
236
236
algorithms, separating multiple algorithms with commas:
237
237
238
238
.. code-block:: java
239
239
240
- ConnectionString connectionString = new ConnectionString("mongodb+srv://<user>:<password>@<cluster-url>?compressors=snappy,zlib,zstd");
240
+ ConnectionString connectionString = new ConnectionString("mongodb+srv://<user>:<password>@<cluster-url>/ ?compressors=snappy,zlib,zstd");
241
241
MongoClient mongoClient = MongoClients.create(connectionString);
242
242
243
243
Specify compression algorithms using the following strings:
@@ -350,12 +350,6 @@ parameters of the connection URI to specify the behavior of the client.
350
350
constraints in other ways, use a
351
351
:ref:`custom SSLContext <tls-custom-sslContext>`.
352
352
353
- * - **sslInvalidHostNameAllowed**
354
- - boolean
355
- - Specifies that the driver should allow invalid hostnames in the
356
- certificate for TLS/SSL connections. Superseded by
357
- **tlsAllowInvalidHostnames**.
358
-
359
353
* - **tlsAllowInvalidHostnames**
360
354
- boolean
361
355
- Specifies that the driver should allow invalid hostnames in the
@@ -383,7 +377,7 @@ parameters of the connection URI to specify the behavior of the client.
383
377
- Specifies the maximum amount of time, in milliseconds, the Java
384
378
driver will continue to use a pooled connection before closing the
385
379
connection.
386
-
380
+
387
381
* - **journal**
388
382
- boolean
389
383
- Specifies that the driver must wait for the connected MongoDB
@@ -477,14 +471,14 @@ parameters of the connection URI to specify the behavior of the client.
477
471
- boolean
478
472
- Specifies that the driver must retry supported read operations
479
473
if they fail due to a network error. Defaults to ``true``.
480
-
474
+
481
475
* - **uuidRepresentation**
482
476
- string
483
477
- Specifies the UUID representation to use for read and write
484
478
operations. For more information, see the the driver documentation
485
479
for the
486
480
`MongoClientSettings.getUuidRepresentation() method <{+api+}/apidocs/mongodb-driver-core/com/mongodb/MongoClientSettings.html#getUuidRepresentation()>`__.
487
-
481
+
488
482
* - **directConnection**
489
483
- boolean
490
484
- Specifies that the driver must connect to the host directly.
0 commit comments