Skip to content

Commit f1ff5d2

Browse files
biniona-mongodbterakilobyteChris Cho
authored
Docsp 16379 mongo client settings (#117)
Co-authored-by: Nathan <[email protected]> Co-authored-by: Chris Cho <[email protected]>
1 parent 904bef5 commit f1ff5d2

File tree

5 files changed

+57
-0
lines changed

5 files changed

+57
-0
lines changed

source/faq.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,26 @@ For applications that require a mix of the new and legacy APIs, ``com.mongodb.Mo
4141
- Configuration with ``MongoClientSettings`` and ``ConnectionString``, the only difference being that you create instances via constructors instead of a factory class.
4242
- CRUD API using ``MongoDatabase``, and from there, ``MongoCollection``. You can access this API via the ``getDatabase()`` method.
4343

44+
How do I use the ``MongoClientSettings`` class?
45+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
46+
47+
You can use the ``MongoClientSettings`` class to specify configurations for
48+
``MongoClient`` instances. To construct ``MongoClientSettings`` instances, use the
49+
``MongoClientSettings.Builder`` class.
50+
51+
Here are the sections of our documentation that show how to perform different
52+
tasks with the ``MongoClientSettings`` class:
53+
54+
- :ref:`Specify Multiple Hosts <mongo-client-settings-multiple-hosts>`
55+
- :ref:`Enable TLS/SSL <tls-enable>`
56+
- :ref:`Authenticate with Credentials <mongo-client-setting-with-mongo-credential-example>`
57+
- :ref:`Enable Compression <enable-compression>`
58+
- :ref:`Add Listeners For Driver and Database Events <listener-mongo-client-settings-example>`
59+
- :ref:`Get the Default Codec Registry <get-default-codec-registry-example>`
60+
61+
For more information on the ``MongoClientSettings`` class, see the
62+
:java-docs:`API Documentation for MongoClientSettings <apidocs/mongodb-driver-core/com/mongodb/MongoClientSettings.html>`.
63+
4464
POJOs
4565
-----
4666

source/fundamentals/auth.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ Select the :guilabel:`Connection String` or the :guilabel:`MongoCredential`
7272
tab below for instructions and sample code for specifying this authentication
7373
mechanism:
7474

75+
.. _mongo-client-setting-with-mongo-credential-example:
76+
7577
.. tabs::
7678

7779
.. tab::

source/fundamentals/connection.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,37 @@ replica set named "myRs".
126126

127127
mongodb://host1:27017,host2:27017,host3:27017
128128

129+
.. _mongo-client-settings-multiple-hosts:
130+
131+
The following examples show how to specify multiple hosts to a ``MongoClient``
132+
instance using either the ``ConnectionString`` or ``MongoClientSettings`` class.
133+
Select the tab corresponding to the code snippet you would like to see:
134+
135+
.. tabs::
136+
137+
.. tab:: ConnectionString
138+
:tabid: connectionstring
139+
140+
.. code-block:: java
141+
142+
ConnectionString connectionString = new ConnectionString("mongodb://host1:27017,host2:27017,host3:27017");
143+
MongoClient mongoClient = MongoClients.create(connectionString);
144+
145+
.. tab:: MongoClientSettings
146+
:tabid: mongoclientsettings
147+
148+
.. code-block:: java
149+
150+
ServerAddress seed1 = new ServerAddress("host1", 27017);
151+
ServerAddress seed2 = new ServerAddress("host2", 27017);
152+
ServerAddress seed3 = new ServerAddress("host3", 27017);
153+
MongoClientSettings settings = MongoClientSettings.builder()
154+
.applyToClusterSettings(builder ->
155+
builder.hosts(Arrays.asList(seed1, seed2, seed3)))
156+
.build();
157+
MongoClient mongoClient = MongoClients.create(settings);
158+
159+
129160
.. note::
130161

131162
Although it is possible to connect to a replica set deployment by

source/fundamentals/data-formats/document-data-format-pojo.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ requirements:
153153
- ``getDefaultCodecRegistry()`` to retrieve a ``CodecRegistry`` instance from a list of codec providers
154154
- ``fromProviders()`` to create a ``CodecRegistry`` instance from the ``PojoCodecProvider``
155155

156+
.. _get-default-codec-registry-example:
157+
156158
See the code below to see how to instantiate the ``CodecRegistry``:
157159

158160
.. code-block:: java

source/fundamentals/monitoring.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ The following code adds an instance of the ``CommandCounter`` class to a
123123
``MongoClientSettings`` object. The code then runs some database commands to test the
124124
counter.
125125

126+
.. _listener-mongo-client-settings-example:
127+
126128
.. literalinclude:: /includes/fundamentals/code-snippets/Monitoring.java
127129
:language: java
128130
:dedent:

0 commit comments

Comments
 (0)