Skip to content

Commit f4c4dff

Browse files
DOCSP-19024 mongoclientsettings methods (#167)
* added MongoClientSettings methods
1 parent 6206698 commit f4c4dff

File tree

5 files changed

+104
-16
lines changed

5 files changed

+104
-16
lines changed

source/fundamentals/auth.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Authentication Mechanisms
1010
:depth: 2
1111
:class: singlecol
1212

13+
.. _authentication-mechanisms-java:
14+
1315
Overview
1416
--------
1517

source/fundamentals/connection/mongoclientsettings.txt

Lines changed: 96 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ Overview
1515
In this guide, you can learn about the different settings to control
1616
the behavior of your ``MongoClient``.
1717

18+
The following sections describe commonly used settings:
19+
20+
- :ref:`MongoClient Settings <mcs-settings>`
21+
- :ref:`Cluster Settings <mcs-cluster-settings>`
22+
- :ref:`Socket Settings <mcs-socket-settings>`
23+
- :ref:`Connection Pool Settings <mcs-connectionpool-settings>`
24+
- :ref:`Server Settings <mcs-server-settings>`
25+
- :ref:`TLS/SSL Settings <mcs-ssl-settings>`
26+
27+
.. _mcs-settings:
28+
29+
MongoClient Settings
30+
--------------------
31+
1832
You can control the behavior of your ``MongoClient`` by creating and passing in a
1933
`MongoClientSettings <{+api+}/apidocs/mongodb-driver-core/com/mongodb/MongoClientSettings.html>`__
2034
object to the `MongoClients.create() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoClients.html#create(com.mongodb.MongoClientSettings)>`__
@@ -25,6 +39,88 @@ To create a ``MongoClientSettings`` object, use the
2539
your desired settings. After chaining all the settings you want, use the
2640
``build()`` method to create the ``MongoClientSettings`` object.
2741

42+
The following table describes all the methods you can chain to your
43+
settings to modify the driver's behavior:
44+
45+
.. list-table::
46+
:widths: 40 60
47+
:header-rows: 1
48+
49+
* - Method
50+
- Description
51+
52+
* - ``addCommandListener()``
53+
- Adds a listener for :ref:`command events <command-events-java>`.
54+
55+
* - ``applicationName​()``
56+
- Sets the logical name of the application using the ``MongoClient``.
57+
58+
* - ``applyConnectionString()``
59+
- Applies the settings from the given ``ConnectionString`` to the builder. If you omit this method, the driver attempts to connect to ``localhost``.
60+
61+
* - ``applyToClusterSettings()``
62+
- Applies the ``ClusterSettings.Builder`` block and then sets the :ref:`cluster settings <mcs-cluster-settings>`.
63+
64+
* - ``applyToConnectionPoolSettings()``
65+
- Applies the ``ConnectionPoolSettings.Builder`` block and then sets the :ref:`connection pool settings <mcs-connectionpool-settings>`.
66+
67+
* - ``applyToServerSettings()``
68+
- Applies the ``ServerSettings.Builder`` block and then sets the :ref:`server settings <mcs-server-settings>`.
69+
70+
* - ``applyToSocketSettings()``
71+
- Applies the ``SocketSettings.Builder`` block and then sets the :ref:`socket settings <mcs-socket-settings>`.
72+
73+
* - ``applyToSslSettings()``
74+
- Applies the ``SslSettings.Builder`` block and then sets the :ref:`TLS/SSL settings <mcs-ssl-settings>`.
75+
76+
* - ``autoEncryptionSettings()``
77+
- | Sets the :ref:`auto-encryption settings <auto-encryption-decryption-java>`.
78+
|
79+
| If you omit ``keyVaultClient`` or set
80+
| ``bypassAutomaticEncryption`` to false in your
81+
| ``AutoEncryptionSettings``, the driver creates a separate,
82+
| internal ``MongoClient``.
83+
|
84+
| The internal ``MongoClient`` configuration differs from the
85+
| parent ``MongoClient`` by setting the ``minPoolSize`` to 0 and
86+
| omitting the ``AutoEncryptionSettings``.
87+
88+
* - ``codecRegistry()``
89+
- Sets the :ref:`codec registry <codecs-codecregistry>`.
90+
91+
* - ``commandListenerList()``
92+
- Sets the :ref:`command listeners <command-events-java>`.
93+
94+
* - ``compressorList()``
95+
- Sets the :ref:`compressors <compression>` to use for compressing messages to the server.
96+
97+
* - ``credential()``
98+
- Sets the :ref:`credential <authentication-mechanisms-java>`.
99+
100+
* - ``readConcern​()``
101+
- Sets the :manual:`read concern </reference/read-concern/>`.
102+
103+
* - ``readPreference()``
104+
- Sets the :manual:`read preference </core/read-preference/>`.
105+
106+
* - ``retryReads()``
107+
- Whether the driver should :manual:`retry reads </core/retryable-reads/>` if a network error occurs.
108+
109+
* - ``retryWrites​()``
110+
- Whether the driver should :manual:`retry writes </core/retryable-writes/>` if a network error occurs.
111+
112+
* - ``serverApi​()``
113+
- Sets the :ref:`server API <versioned-api-java>` to use when sending commands to the server.
114+
115+
* - ``streamFactoryFactory()``
116+
- Sets the factory to use to create a ``StreamFactory``.
117+
118+
* - ``uuidRepresentation()``
119+
- Sets the UUID representation to use when encoding instances of UUID and decoding BSON binary values with subtype of 3.
120+
121+
* - ``writeConcern​()``
122+
- Sets the :manual:`write concern </reference/write-concern/>`.
123+
28124
.. _connection-string-example:
29125

30126
Example
@@ -39,22 +135,6 @@ This example demonstrates specifying a ``ConnectionString``:
39135
:emphasize-lines: 3
40136
:dedent:
41137

42-
.. tip::
43-
44-
If you omit the ``applyConnectionString()`` method, the driver
45-
attempts to connect to ``localhost``.
46-
47-
For a list of methods available in ``MongoClientSettings``,
48-
see the `API Documentation <{+api+}/apidocs/mongodb-driver-core/com/mongodb/MongoClientSettings.Builder.html>`__.
49-
50-
The following sections describe commonly used settings:
51-
52-
- :ref:`Cluster Settings <mcs-cluster-settings>`
53-
- :ref:`Socket Settings <mcs-socket-settings>`
54-
- :ref:`Connection Pool Settings <mcs-connectionpool-settings>`
55-
- :ref:`Server Settings <mcs-server-settings>`
56-
- :ref:`TLS/SSL Settings <mcs-ssl-settings>`
57-
58138
.. tip::
59139

60140
Each setting has an ``applyConnectionString()`` method. They are

source/fundamentals/csfle.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ services from AWS, Azure, and GCP. Each example program execution creates a new
8585
MongoDB recommends using local key management only for testing purposes, and using a remote key management service
8686
for production.
8787

88+
.. _auto-encryption-decryption-java:
89+
8890
Automatic Encryption and Decryption
8991
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9092

source/fundamentals/monitoring.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ The following sections show how to monitor each event category.
6868
For a full list of the events you can monitor,
6969
`see the event package of the MongoDB Java Driver <{+api+}/apidocs/mongodb-driver-core/com/mongodb/event/package-summary.html>`__.
7070

71+
.. _command-events-java:
72+
7173
Command Events
7274
~~~~~~~~~~~~~~
7375

source/fundamentals/versioned-api.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Versioned API
1010
:depth: 1
1111
:class: singlecol
1212

13+
.. _versioned-api-java:
14+
1315
.. note::
1416

1517
The Versioned API feature requires MongoDB Server 5.0 or later.

0 commit comments

Comments
 (0)