Skip to content

Commit c426518

Browse files
committed
RL tech PR fixes 1
1 parent e040907 commit c426518

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

source/connect/connection-options.txt

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,36 @@ the settings object to the ``MongoClient.create()`` method.
5252
Configuring the connection this way makes it easier to
5353
change settings at runtime and can help you catch errors at compile time.
5454

55-
The following example shows how to set options when creating a
56-
``MongoClientSettings`` instance:
55+
The following example shows how to specify your connection target and
56+
set other options when creating a ``MongoClientSettings`` instance:
5757

5858
.. code-block:: kotlin
5959

60-
val uri = "<connection string>"
61-
6260
val settings = MongoClientSettings.builder()
63-
.applyConnectionString(ConnectionString(uri))
64-
.retryWrites(true)
61+
.applyToClusterSettings { builder -> builder.hosts(listOf(ServerAddress("localhost", 27017))) }
62+
.applyToSocketSettings { builder -> builder.connectTimeout(60000, TimeUnit.MILLISECONDS) }
63+
.applyToSslSettings { builder -> builder.enabled(true) }
6564
.build()
6665

6766
val mongoClient = MongoClient.create(settings)
6867

68+
If you prefer to provide a connection string instead of specifying
69+
the hostname and port, you can use the ``applyConnectionString()``
70+
method, then set other options by using builder methods, as shown in the
71+
following code:
72+
73+
.. code-block:: kotlin
74+
:emphasize-lines: 1, 3
75+
76+
val uri = "<connection string>"
77+
val settings = MongoClientSettings.builder()
78+
.applyConnectionString(ConnectionString(uri))
79+
.applyToSocketSettings { builder -> builder.connectTimeout(60000, TimeUnit.MILLISECONDS) }
80+
.applyToSslSettings { builder -> builder.enabled(true) }
81+
.build()
82+
83+
val mongoClient = MongoClient.create(settings)
84+
6985
Connection Options
7086
------------------
7187

0 commit comments

Comments
 (0)