Skip to content

Commit d1d8bd8

Browse files
committed
tabs
1 parent 75c60a0 commit d1d8bd8

File tree

8 files changed

+437
-389
lines changed

8 files changed

+437
-389
lines changed

source/connection/specify-connection-options.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Specify Connection Options
1010
MongoClient Settings </connection/specify-connection-options/mongoclientsettings>
1111
Stable API </connection/specify-connection-options/stable-api>
1212
Connection Pools </connection/specify-connection-options/connection-pools>
13+
Cluster Settings </connection/specify-connection-options/cluster-settings>
1314
Network Compression </connection/specify-connection-options/network-compression>
1415
JNDI Datasource </connection/specify-connection-options/jndi>
1516
AWS Lambda <https://www.mongodb.com/docs/atlas/manage-connections-aws-lambda/>
@@ -27,7 +28,4 @@ Overview
2728

2829
This section describes the MongoDB connection and authentication options
2930
available in the {+driver-short+}. You can specify connection options in the
30-
following ways:
31-
32-
- :ref:`Specifying query parameters in the connection URI<java-connection-uri-options>` you pass to the ``MongoClient`` constructor
33-
- :ref:`Defining a MongoClientSettings object <mongoclientsettings>` and passing it to the ``MongoClient`` constructor
31+
following ways:
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
.. _mcs-cluster-settings:
2+
3+
================
4+
Cluster Settings
5+
================
6+
7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 2
11+
:class: singlecol
12+
13+
.. facet::
14+
:name: genre
15+
:values: reference
16+
17+
.. meta::
18+
:keywords: timeout, replica set
19+
20+
Overview
21+
--------
22+
23+
In this guide, you can learn about how the {+driver-short+} manages clusters.
24+
25+
You can specify settings for your clusters using either a :ref:`connection
26+
string <connection-uri>` or by passing a ``MongoClientSettings`` object to the
27+
:ref:`MongoClients <mongoclient>` contructor. Select the :guilabel:`Connection
28+
String` or :guilabel:`MongoClientSettings` tab to see the options available:
29+
30+
31+
.. tabs::
32+
33+
.. tab:: Connection String
34+
:tabid: uri
35+
36+
.. list-table::
37+
:header-rows: 1
38+
:widths: 20 10 20
39+
40+
* - Option Name
41+
- Type
42+
- Description
43+
44+
* - **serverSelectionTimeoutMS**
45+
- integer
46+
- Specifies the maximum amount of time, in milliseconds, the driver
47+
will wait for server selection to succeed before throwing an
48+
exception.
49+
50+
| **Default**: ``30000`` (30 seconds)
51+
52+
* - **localThresholdMS**
53+
- integer
54+
- When communicating with multiple instances of MongoDB in a replica
55+
set, the driver will only send requests to a server whose
56+
response time is less than or equal to the server with the fastest
57+
response time plus the local threshold, in milliseconds.
58+
59+
| **Default**: ``15``
60+
61+
* - **heartbeatFrequencyMS**
62+
- integer
63+
- Specifies the frequency, in milliseconds that the driver will
64+
wait between attempts to determine the current state of each
65+
server in the cluster.
66+
67+
| **Default**: ``10000`` (10 seconds)
68+
69+
* - **replicaSet**
70+
- string
71+
- Specifies that the :ref:`connection string <connection-uri>`
72+
provided includes multiple hosts. When specified, the driver
73+
attempts to find all members of that set.
74+
75+
| **Default**: ``null``
76+
77+
* - **directConnection**
78+
- boolean
79+
- Specifies that the driver must connect to the host directly. This
80+
maps to applying ``mode(ClusterConnectionMode.SINGLE)`` to your ``MongoClientSettings``.
81+
82+
| **Default**: ``false``
83+
84+
* - **srvServiceName**
85+
- string
86+
- Specifies the service name of the `SRV resource records <https://www.rfc-editor.org/rfc/rfc2782>`__ the driver retrieves to construct your :manual:`seed list </reference/glossary/#std-term-seed-list>`. You must use the :manual:`DNS Seed List Connection Format </reference/connection-string/#dns-seed-list-connection-format>` in your :ref:`connection URI <connection-uri>` to use this option.
87+
88+
| **Default**: ``mongodb``
89+
90+
.. tab:: MongoClientSettings
91+
:tabid: MongoClient
92+
93+
Chain the `applyToClusterSettings()
94+
<{+api+}/apidocs/mongodb-driver-core/com/mongodb/MongoClientSettings.Builder.html#applyToClusterSettings(com.mongodb.Block)>`__
95+
method to modify the driver's behavior when interacting with your MongoDB
96+
cluster.
97+
98+
The following table describes the methods you can chain to your
99+
settings to modify the driver's behavior:
100+
101+
.. list-table::
102+
:header-rows: 1
103+
:stub-columns: 1
104+
:widths: 40 60
105+
106+
* - Method
107+
- Description
108+
109+
* - ``addClusterListener()``
110+
- Adds a listener for cluster-related events.
111+
112+
* - ``applyConnectionString()``
113+
- Uses the settings from a ``ConnectionString`` object.
114+
115+
* - ``applySettings()``
116+
- Uses the cluster settings specified in a ``ClusterSettings`` object.
117+
118+
* - ``hosts()``
119+
- Sets all the specified locations of a Mongo deployment.
120+
121+
* - ``localThreshold()``
122+
- | Sets the amount of time that a server’s round trip can take and still be eligible for server selection.
123+
|
124+
| **Default**: ``15 milliseconds``
125+
126+
* - ``mode()``
127+
- Sets how to connect to a MongoDB deployment.
128+
129+
* - ``requiredClusterType()``
130+
- Sets the type of cluster required for the cluster.
131+
132+
* - ``requiredReplicaSetName()``
133+
- Sets the replica set name required for the cluster.
134+
135+
* - ``serverSelectionTimeout()``
136+
- | Sets the maximum time to select a primary node before throwing a timeout exception.
137+
|
138+
| **Default**: ``30 seconds``
139+
140+
* - ``serverSelector()``
141+
- Adds a server selector to apply before server selection.
142+
143+
* - ``srvHost()``
144+
- | Sets the host name to use to look up an SRV DNS record to find the MongoDB hosts.
145+
|
146+
| If you want to enable the processing of TXT records associated with the host, specify the SRV host in the connection string using the ``applyConnectionString()`` method.
147+
|
148+
| For example:
149+
150+
.. code-block:: java
151+
:emphasize-lines: 3
152+
153+
MongoClient mongoClient =
154+
MongoClients.create(MongoClientSettings.builder()
155+
.applyConnectionString(new ConnectionString("mongodb+srv://host1.acme.com")))
156+
157+
* - ``srvMaxHosts()``
158+
- | Sets the maximum number of hosts the driver can connect to when using the DNS seedlist (SRV) connection protocol, identified by the ``mongodb+srv`` connection string prefix.
159+
|
160+
| Throws an exception if you are not using the SRV connection protocol.
161+
162+
Example
163+
~~~~~~~
164+
165+
This example specifies for the driver to connect directly to a server,
166+
regardless of the type of MongoDB cluster it's a part of:
167+
168+
.. literalinclude:: /includes/fundamentals/code-snippets/MCSettings.java
169+
:start-after: begin ClusterSettings
170+
:end-before: end ClusterSettings
171+
:language: java
172+
:emphasize-lines: 3-4
173+
:dedent:
174+
175+
.. tip::
176+
177+
This is analogous to the ``directConnection`` parameter you can specify
178+
in your connection URI. See :ref:`<connection-options>` for more
179+
information.

source/connection/specify-connection-options/connection-pools.txt

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.. _java-connection-pools:
2+
.. _mcs-connectionpool-settings:
23

34
================
45
Connection Pools
@@ -117,7 +118,13 @@ see the corresponding syntax:
117118
.. tab:: MongoClientSettings
118119
:tabid: MongoClient
119120

120-
Chain the `applyToConnectionPoolSettings() <{+api+}/apidocs/mongodb-driver-core/com/mongodb/MongoClientSettings.Builder.html#applyToConnectionPoolSettings(com.mongodb.Block)>`__ method to modify the way the driver manages its connection pool.
121+
Chain the `applyToConnectionPoolSettings() <{+api+}/apidocs/mongodb-driver-core/com/mongodb/MongoClientSettings.Builder.html#applyToConnectionPoolSettings(com.mongodb.Block)>`__ method to modify the way the driver manages its connection pool. The following example chains the ``applyToConnectionPoolSettings()`` method to set the thread to wait at most ``10 SECONDS`` for an available connection, and the ``maxSize`` of the connection pool to 200:
122+
123+
.. literalinclude:: /includes/fundamentals/code-snippets/ConnectionPool.java
124+
:start-after: begin MongoSettings
125+
:end-before: end MongoSettings
126+
:language: java
127+
:dedent:
121128

122129
The following table describes the methods you can chain to your settings to modify the driver's behavior:
123130

@@ -172,17 +179,7 @@ see the corresponding syntax:
172179

173180
This ``maxSize`` and ``minSize`` settings apply to each server in the cluster you connect the driver to.
174181

175-
For example, assume you connect the driver to a cluster with three``mongos`` servers. This means that there can be at most ``maxSize`` connections and at least ``minSize`` connections to each ``mongos`` server.
176-
177-
.. literalinclude:: /includes/fundamentals/code-snippets/ConnectionPool.java
178-
:start-after: begin MongoSettings
179-
:end-before: end MongoSettings
180-
:language: java
181-
:dedent:
182-
183-
For more information on configuring you connection pool by using a
184-
``MongoClientSettings`` object see the Connection Pool Settings section
185-
of the :ref:`<specify-mongoclient-settings>` guide.
182+
For example, assume you connect the driver to a cluster with three ``mongos`` servers. This means that there can be at most ``maxSize`` connections and at least ``minSize`` connections to each ``mongos`` server.
186183

187184
Additional Information
188185
----------------------

0 commit comments

Comments
 (0)