Skip to content

Commit 4e62dff

Browse files
DOCSP-18073 connection guide update (#156)
* updated connection URI and connection options sections
1 parent 3243eb4 commit 4e62dff

26 files changed

+60
-67
lines changed

source/fundamentals/aggregation.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Connect to a MongoDB Deployment
9191

9292
public static void main(String[] args) {
9393
// Replace the uri string with your MongoDB deployment's connection string
94-
String uri = "mongodb+srv://<user>:<password>@<cluster-url>?retryWrites=true&w=majority";
94+
String uri = "<connection string uri>";
9595

9696
MongoClient mongoClient = MongoClients.create(uri);
9797
MongoDatabase database = mongoClient.getDatabase("aggregation");

source/fundamentals/connection.txt

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -47,46 +47,45 @@ usage limits, such as max connections, apply to individual
4747

4848
.. _connection-uri:
4949

50-
Connection String
51-
-----------------
50+
Connection URI
51+
--------------
5252

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:
5857

59-
.. figure:: /includes/figures/connection_string_parts.png
58+
.. figure:: /includes/figures/connection_uri_parts.png
6059
:alt: Connection String parts figure
6160

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.
6867

6968
.. note::
7069

71-
If your deployment is on MongoDB Atlas, follow the
70+
If your deployment is on MongoDB Atlas, see the
7271
: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.
7473

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.
8079

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.
8584

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.
9089

9190
.. _connect-atlas-java-driver:
9291

@@ -95,6 +94,7 @@ connect to MongoDB.
9594

9695
.. literalinclude:: /includes/fundamentals/code-snippets/srv.java
9796
:language: java
97+
:emphasize-lines: 17
9898

9999
.. _java-other-ways-to-connect:
100100

@@ -159,7 +159,7 @@ Select the tab corresponding to the code snippet you would like to see:
159159

160160
.. code-block:: java
161161

162-
ConnectionString connectionString = new ConnectionString("mongodb://host1:27017,host2:27017,host3:27017");
162+
ConnectionString connectionString = new ConnectionString("mongodb://host1:27017,host2:27017,host3:27017/");
163163
MongoClient mongoClient = MongoClients.create(connectionString);
164164

165165
.. tab:: MongoClientSettings
@@ -230,14 +230,14 @@ using a method in the ``MongoClientSettings.Builder`` class.
230230
:tabid: connectionstring
231231

232232
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``
234234
in the connection string passed to
235235
``MongoClients.create()``. You can specify one or more compression
236236
algorithms, separating multiple algorithms with commas:
237237

238238
.. code-block:: java
239239

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");
241241
MongoClient mongoClient = MongoClients.create(connectionString);
242242

243243
Specify compression algorithms using the following strings:
@@ -350,12 +350,6 @@ parameters of the connection URI to specify the behavior of the client.
350350
constraints in other ways, use a
351351
:ref:`custom SSLContext <tls-custom-sslContext>`.
352352

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-
359353
* - **tlsAllowInvalidHostnames**
360354
- boolean
361355
- 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.
383377
- Specifies the maximum amount of time, in milliseconds, the Java
384378
driver will continue to use a pooled connection before closing the
385379
connection.
386-
380+
387381
* - **journal**
388382
- boolean
389383
- 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.
477471
- boolean
478472
- Specifies that the driver must retry supported read operations
479473
if they fail due to a network error. Defaults to ``true``.
480-
474+
481475
* - **uuidRepresentation**
482476
- string
483477
- Specifies the UUID representation to use for read and write
484478
operations. For more information, see the the driver documentation
485479
for the
486480
`MongoClientSettings.getUuidRepresentation() method <{+api+}/apidocs/mongodb-driver-core/com/mongodb/MongoClientSettings.html#getUuidRepresentation()>`__.
487-
481+
488482
* - **directConnection**
489483
- boolean
490484
- Specifies that the driver must connect to the host directly.

source/fundamentals/connection/jndi.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ JNDI DataSource.
4545
<bindings>
4646
<object-factory name="java:global/MyMongoClient" module="org.mongodb" class="com.mongodb.client.MongoClientFactory">
4747
<environment>
48-
<property name="connectionString" value="mongodb+srv://<user>:<password>@<cluster-url>?retryWrites=true&w=majority"/>
48+
<property name="connectionString" value="<connection string uri>"/>
4949
</environment>
5050
</object-factory>
5151
</bindings>
@@ -78,7 +78,7 @@ JNDI DataSource.
7878
closeMethod="close"
7979
factory="com.mongodb.client.MongoClientFactory"
8080
singleton="true"
81-
connectionString="mongodb+srv://<user>:<password>@<cluster-url>?retryWrites=true&w=majority"/>
81+
connectionString="<connection string uri>"/>
8282

8383
.. note::
8484

-6.26 KB
Binary file not shown.
5.92 KB
Loading

source/includes/fundamentals/code-snippets/AggTour.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
public class AggTour {
2323
public static void main(String[] args) {
2424
// Replace the uri string with your MongoDB deployment's connection string
25-
final String uri = "mongodb+srv://<user>:<password>@<cluster-url>?retryWrites=true&w=majority";
25+
final String uri = "<connection string uri>";
2626

2727
MongoClient mongoClient = MongoClients.create(uri);
2828
MongoDatabase database = mongoClient.getDatabase("aggregation");

source/includes/fundamentals/code-snippets/VersionedApiExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static void main(String[] args) {
2525
.build();
2626

2727
// Replace the uri string with your MongoDB deployment's connection string
28-
String uri = "mongodb+srv://<user>:<password>@<cluster-url>?retryWrites=true&w=majority";
28+
String uri = "<connection string uri>";
2929

3030
MongoClientSettings settings = MongoClientSettings.builder()
3131
.applyConnectionString(new ConnectionString(uri))

source/includes/fundamentals/code-snippets/srv.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
import com.mongodb.client.MongoClients;
1212
import com.mongodb.client.MongoDatabase;
1313

14-
1514
public class RunCommand {
1615
public static void main(String[] args) {
1716
// Replace the uri string with your MongoDB deployment's connection string
18-
String uri = "mongodb+srv://<user>:<password>@<cluster-url>?retryWrites=true&w=majority";
17+
String uri = "mongodb://user:[email protected]:27017/?maxPoolSize=20&w=majority";
1918

2019
try (MongoClient mongoClient = MongoClients.create(uri)) {
2120

source/includes/quick-start/code-snippets/QuickStart.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
public static void main( String[] args ) {
1414

1515
// Replace the uri string with your MongoDB deployment's connection string
16-
String uri = "mongodb+srv://<user>:<password>@<cluster-url>?retryWrites=true&w=majority";
16+
String uri = "<connection string uri>";
1717

1818
try (MongoClient mongoClient = MongoClients.create(uri)) {
1919
MongoDatabase database = mongoClient.getDatabase("sample_mflix");

source/includes/quick-start/code-snippets/QuickStartPojoExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static void main(String[] args) {
2222
CodecRegistry pojoCodecRegistry = fromRegistries(getDefaultCodecRegistry(), fromProviders(pojoCodecProvider));
2323

2424
// Replace the uri string with your MongoDB deployment's connection string
25-
String uri = "mongodb+srv://<user>:<password>@<cluster-url>?retryWrites=true&w=majority";
25+
String uri = "<connection string uri>";
2626

2727
try (MongoClient mongoClient = MongoClients.create(uri)) {
2828
MongoDatabase database = mongoClient.getDatabase("sample_mflix").withCodecRegistry(pojoCodecRegistry);

0 commit comments

Comments
 (0)