@@ -39,20 +39,20 @@ To specify a timeout when connecting to a MongoDB deployment, set the
39
39
``timeoutMS`` connection option to the timeout length in milliseconds. You can
40
40
set the ``timeoutMS`` option in the following ways:
41
41
42
- - Using the ``timeout()`` method from the
42
+ - Calling the ``timeout()`` method from the
43
43
``MongoClientSettings.Builder`` class
44
44
- Setting the ``timeoutMS`` parameter in your connection string
45
45
46
- Select from the following :guilabel:`MongoClientSettings` and
47
- :guilabel:`Connection String` tabs to view how to set a client-level
48
- timeout of 5 seconds by using each method:
46
+ The following code examples set a client-level timeout of ``5`` seconds.
47
+ Select the :guilabel:`MongoClientSettings` or :guilabel:`Connection
48
+ String` tab to see the corresponding code.
49
49
50
50
.. tabs::
51
51
52
52
.. tab:: MongoClientSettings
53
53
:tabid: mongoclientsettings
54
54
55
- .. literalinclude:: /includes/connect/CSOT .java
55
+ .. literalinclude:: /includes/connect/CsotExample .java
56
56
:language: java
57
57
:start-after: start-mongoclientsettings
58
58
:end-before: end-mongoclientsettings
@@ -62,14 +62,14 @@ timeout of 5 seconds by using each method:
62
62
.. tab:: Connection String
63
63
:tabid: connection-string
64
64
65
- .. literalinclude:: /includes/connect/CSOT .java
65
+ .. literalinclude:: /includes/connect/CsotExample .java
66
66
:language: java
67
67
:start-after: start-string
68
68
:end-before: end-string
69
69
:dedent:
70
70
71
- Behavior
72
- ~~~~~~~~
71
+ Accepted Timeout Values
72
+ ~~~~~~~~~~~~~~~~~~~~~~~
73
73
74
74
The following table describes the timeout behavior corresponding to the
75
75
accepted values for ``timeoutMS``:
@@ -81,11 +81,11 @@ accepted values for ``timeoutMS``:
81
81
* - Value
82
82
- Behavior
83
83
84
- * - Positive value
84
+ * - Positive integer
85
85
- Sets the timeout to use for operation completion.
86
86
87
87
* - ``0``
88
- - Sets an infinite timeout .
88
+ - Specifies that operations never time out .
89
89
90
90
* - ``null`` or unset
91
91
- | Defers the timeout behavior to the following settings:
@@ -99,11 +99,11 @@ accepted values for ``timeoutMS``:
99
99
| These settings are deprecated and are ignored if you set ``timeoutMS``.
100
100
101
101
If you specify the ``timeoutMS`` option, the driver automatically applies the
102
- specified timeout for each server operation. The following code example specifies
103
- a timeout of 5 seconds at the client level, and then calls the
102
+ specified timeout to each server operation. The following code example specifies
103
+ a timeout of ``5`` seconds at the client level, and then calls the
104
104
``MongoCollection.insertOne()`` method:
105
105
106
- .. literalinclude:: /includes/connect/CSOT .java
106
+ .. literalinclude:: /includes/connect/CsotExample .java
107
107
:language: java
108
108
:start-after: start-operation-timeout
109
109
:end-before: end-operation-timeout
@@ -124,24 +124,27 @@ The following table describes how the timeout value is inherited at each level:
124
124
- Inheritance Description
125
125
126
126
* - Operation
127
- - Takes the highest precedence and will override ``timeoutMS``
128
- options set at any other level.
127
+ - Takes the highest precedence and overrides the timeout
128
+ options that you set at any other level.
129
129
130
130
* - Transaction
131
- - Takes precedence over ``timeoutMS`` set at the session,
131
+ - Takes precedence over the timeout value that you set at the session,
132
132
collection, database, or client level.
133
133
134
134
* - Session
135
135
- Applies to all transactions and operations within
136
- that session, unless the option is overridden by options set at those levels.
136
+ that session, unless you set a different timeout value at those
137
+ levels.
137
138
138
139
* - Database
139
140
- Applies to all sessions and operations within that
140
- database, unless the option is overridden by options set at those levels.
141
+ database, unless you set a different timeout value at those
142
+ levels.
141
143
142
144
* - Collection
143
145
- Applies to all sessions and operations on that
144
- collection, unless the option is overridden by options set at those levels.
146
+ collection, unless you set a different timeout value at those
147
+ levels.
145
148
146
149
* - Client
147
150
- Applies to all databases, collections, sessions, transactions, and
@@ -159,14 +162,15 @@ Overrides
159
162
The {+driver-short+} supports various levels of configuration to control the
160
163
behavior and performance of database operations.
161
164
162
- You can specify a ``timeoutMS`` option at a lower level to override the
163
- client-level configuration. This allows you to customize timeouts based
164
- on the needs of individual operations.
165
+ You can specify a ``timeoutMS`` option at a more specific level to override the
166
+ client-level configuration. The table in the preceding section describes
167
+ the levels at which you can specify a timeout setting. This allows you
168
+ to customize timeouts based on the needs of individual operations.
165
169
166
170
The following example demonstrates how a collection-level timeout
167
171
configuration can override a client-level timeout configuration:
168
172
169
- .. literalinclude:: /includes/connect/CSOT .java
173
+ .. literalinclude:: /includes/connect/CsotExample .java
170
174
:language: java
171
175
:start-after: start-override
172
176
:end-before: end-override
@@ -182,7 +186,7 @@ When you create a new `ClientSession
182
186
<{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/ClientSession.html>`__
183
187
instance to implement a transaction, use
184
188
the ``defaultTimeout()`` method when building a ``ClientSessionOptions``
185
- instance. You can use this option to specify the timeout to apply for
189
+ instance. You can use this option to specify the timeout for
186
190
the following methods:
187
191
188
192
- `commitTransaction() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/ClientSession.html#commitTransaction()>`__
@@ -193,7 +197,7 @@ the following methods:
193
197
The following code demonstrates how to set the ``defaultTimeout`` when
194
198
instantiating a ``ClientSession``:
195
199
196
- .. literalinclude:: /includes/connect/CSOT .java
200
+ .. literalinclude:: /includes/connect/CsotExample .java
197
201
:language: java
198
202
:start-after: start-session-timeout
199
203
:end-before: end-session-timeout
@@ -202,12 +206,12 @@ instantiating a ``ClientSession``:
202
206
If you do not specify the ``defaultTimeout``, the driver uses the timeout
203
207
value set on the parent ``MongoClient``.
204
208
205
- You can also set a transaction-level timeout by using the ``timeout()``
209
+ You can also set a transaction-level timeout by calling the ``timeout()``
206
210
method when building a ``TransactionOptions`` instance. Setting this
207
211
option applies a timeout to all operations performed in the scope of the
208
212
transaction:
209
213
210
- .. literalinclude:: /includes/connect/CSOT .java
214
+ .. literalinclude:: /includes/connect/CsotExample .java
211
215
:language: java
212
216
:start-after: start-txn-timeout
213
217
:end-before: end-txn-timeout
@@ -221,17 +225,17 @@ Client Encryption
221
225
When you use Client-Side Field Level Encryption (CSFLE), the driver uses the
222
226
``timeoutMS`` option to limit the time allowed for encryption and decryption
223
227
operations. You can set a timeout option for your ``ClientEncryption``
224
- instance by using the ``timeout()`` method when building a
228
+ instance by calling the ``timeout()`` method when building a
225
229
``ClientEncryptionSettings`` instance.
226
230
227
231
If you specify the timeout when you construct a
228
- ``ClientEncryption`` instance, it controls the lifetime of all operations
232
+ ``ClientEncryption`` instance, the timeout controls the lifetime of all operations
229
233
performed on that instance. If you do not provide a timeout when
230
234
instantiating ``ClientEncryption``, the instance
231
235
inherits the timeout setting from the ``MongoClient`` used in the
232
236
``ClientEncryption`` constructor.
233
237
234
- If you set ``timeoutMS`` on both the client and directly in
238
+ If you set ``timeoutMS`` both on the client and directly in
235
239
``ClientEncryption``, the value provided to ``ClientEncryption`` takes
236
240
precedence.
237
241
@@ -261,10 +265,10 @@ Cursor Lifetime Mode
261
265
~~~~~~~~~~~~~~~~~~~~
262
266
263
267
The cursor lifetime mode uses the timeout setting to limit the entire lifetime of a
264
- cursor. In this mode, the initialization of the cursor and all subsequent calls
265
- to the cursor methods must complete within the limit specified by the
266
- timeout option. All documents must be returned within this limit.
267
- Otherwise, the cursor's lifetime expires and a timeout error occurs .
268
+ cursor. In this mode, your application must initialize the cursor, complete
269
+ all calls to the cursor methods, and return all documents within the specified
270
+ time limit. Otherwise, the cursor's lifetime expires and the driver
271
+ raises a timeout error.
268
272
269
273
When you close a cursor by calling the ``close()`` method, the
270
274
timeout resets for the ``killCursors`` command to ensure server-side resources are
@@ -274,7 +278,7 @@ The following example shows how to set a cursor timeout to ensure that
274
278
the cursor is initialized and all documents are retrieved within the
275
279
inherited timeout:
276
280
277
- .. literalinclude:: /includes/connect/CSOT .java
281
+ .. literalinclude:: /includes/connect/CsotExample .java
278
282
:language: java
279
283
:start-after: start-cursor-lifetime
280
284
:end-before: end-cursor-lifetime
@@ -294,7 +298,7 @@ The following code example iterates over documents in the ``db.people`` collecti
294
298
by using a cursor with the ``ITERATION`` timeout mode, and then retrieves
295
299
and prints the ``name`` field value for each document:
296
300
297
- .. literalinclude:: /includes/connect/CSOT .java
301
+ .. literalinclude:: /includes/connect/CsotExample .java
298
302
:language: java
299
303
:start-after: start-cursor-iteration
300
304
:end-before: end-cursor-iteration
0 commit comments