@@ -15,7 +15,7 @@ Customize Server Selection
15
15
:values: reference
16
16
17
17
.. meta::
18
- :keywords: read preference, write
18
+ :keywords: read preference, write, server selection
19
19
20
20
Overview
21
21
--------
@@ -37,26 +37,26 @@ in order, to select a MongoDB deployment:
37
37
38
38
1. Selects all servers that match the active read preference from the list of known servers.
39
39
40
- #. If at least one readable server exists, the driver calls the user-defined
41
- server-selector function and passes in the list from the previous step.
40
+ #. If at least one readable server exists, calls the user-defined
41
+ server-selector function and passes in the list from the previous step
42
42
43
43
#. Applies the ``localThreshold`` connection setting to the list of
44
- servers returned from the function.
44
+ servers returned from the function
45
45
46
46
#. Selects a server at random from the servers still on the list and
47
- executes the operation against this server.
47
+ executes the operation against this server
48
48
49
49
When the {+driver-short+} executes a write operation, it begins by selecting all writeable
50
- servers, not just those that match the active read preference. The remaining steps are
51
- identical.
50
+ servers from the list of known servers , not just those that match the active read preference.
51
+ The remaining steps are identical to the preceding list .
52
52
53
53
To learn more about the default server selection algorithm, which the driver follows
54
54
when you don't specify any custom server selection logic, see
55
55
:manual:`Server Selection Algorithm </core/read-preference-mechanics/>` in the
56
56
{+mdb-server+} manual.
57
57
58
- Implementing Custom Server Selection Logic
59
- ------------------------------------------
58
+ Implement Custom Server Selection Logic
59
+ ---------------------------------------
60
60
61
61
You can implement your own custom server selection logic by creating a class that
62
62
implements the ``ServerSelector`` interface and overrides the ``select()`` method. The following
@@ -69,18 +69,18 @@ value of ``ServerType.REPLICA_SET_SECONDARY``:
69
69
:start-after: // start-custom-selector
70
70
:end-before: // end-custom-selector
71
71
72
- You can then pass an instance of this class to your ``MongoClientSettings`` object by
73
- using the ``applyToClusterSettings()`` method . The following example shows how to create
74
- a ``MongoClient`` with an instance of the custom server selector from the preceding example:
72
+ Use the ``applyToClusterSettings()`` method to pass an instance of this class to your
73
+ ``MongoClientSettings`` . The following example shows how to create
74
+ a ``MongoClient`` with an instance of the custom server selector class from the preceding example:
75
75
76
76
.. literalinclude:: /includes/connect/ServerSelection.kt
77
77
:language: kotlin
78
78
:copyable: true
79
79
:start-after: // start-selector
80
80
:end-before: // end-selector
81
81
82
- Using Settings to Configure Server Selection
83
- --------------------------------------------
82
+ Use Settings to Configure Server Selection
83
+ ------------------------------------------
84
84
85
85
You can specify the following server selection settings in your ``MongoClient`` object or
86
86
in your connection URI:
@@ -119,7 +119,7 @@ in your connection URI:
119
119
* - ``serverSelectionTimeout``
120
120
- | The length of time the driver tries to select a server before timing out.
121
121
|
122
- | **Data Type**: ``long ``
122
+ | **Data Type**: ``Long ``
123
123
| **Default**: 30 seconds
124
124
| **Connection URI Example**: ``serverSelectionTimeoutMS=15000``
125
125
0 commit comments