Skip to content

Commit 717d6d1

Browse files
authored
DOCSP-26194: CSOT (#202)
* DOCSP-26194: CSOT * AH PR fixes 1 * content placement
1 parent 121f955 commit 717d6d1

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

source/fundamentals/connection.txt

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ URI to specify the behavior of the client.
143143
- Default Value
144144
- Description
145145

146+
* - **timeoutMS**
147+
- integer
148+
- ``null``
149+
- Specifies the number of milliseconds that a single operation run on the
150+
``Client`` can take before returning a timeout error. Operations honor
151+
this setting only if there is no deadline on the operation Context.
152+
146153
* - **connectTimeoutMS**
147154
- integer
148155
- ``30000``
@@ -219,3 +226,47 @@ URI to specify the behavior of the client.
219226
For a full list of connection options, see the `ClientOptions API
220227
documentation
221228
<{+api+}/mongo/options#ClientOptions>`__.
229+
230+
.. _golang-timeout-setting:
231+
232+
Single Timeout Setting
233+
~~~~~~~~~~~~~~~~~~~~~~
234+
235+
You can set a single ``Timeout`` option on your ``Client`` to govern the
236+
amount of time that a single operation can take to execute using the
237+
``SetTimeout()`` method or specifying the ``timeoutMS`` option in your
238+
connection URI string. ``Database``, ``Collection``,
239+
``Session``, ``ChangeStream``, and ``Bucket`` instances elsewhere in
240+
your code inherit the ``Timeout`` option from ``Client`` if you do not set a
241+
Context for operations against the same entity.
242+
243+
If you pass a Context into an operation with a deadline, the driver uses
244+
that Context deadline for the operation. If the context does not have a
245+
deadline, the driver derives a new Context from the given Context using
246+
the ``Timeout`` option set on the ``Client``.
247+
248+
The following code shows how to set the ``Timeout`` option on a ``Client``
249+
with the ``SetTimeout`` option:
250+
251+
.. code-block:: go
252+
253+
opts := options.Client().SetTimeout(5 * time.Second)
254+
255+
The following example shows how you can set a single timeout with the
256+
URI option and execute an operation that inherits this setting:
257+
258+
.. code-block:: go
259+
260+
uri := "mongodb://user:[email protected]:27017/?timeoutMS=5000"
261+
client := mongo.Connect(uri)
262+
coll := client.Database("<db>").Collection("<collection>")
263+
...
264+
coll.InsertOne(context.Background(), doc)
265+
266+
.. important:: Legacy Timeout Options
267+
268+
``SocketTimeout``, ``wTimeout``, ``MaxTime``, and ``MaxCommitTime``
269+
will be deprecated in an upcoming release. The driver ignores ``MaxTime`` and
270+
``MaxCommitTime`` if you set ``Timeout``. The driver still honors
271+
``SocketTimeout`` and ``wTimeout``, but these settings may result in
272+
undefined behavior. Consider using only the single timeout option instead.

source/fundamentals/context.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ an error.
3535
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
3636
defer cancel()
3737
client.Database("<db>").Collection("<collection>").Insert(ctx, bson.D{{"x",1}})
38+
39+
If the Context passed into an operation does not have a deadline, you
40+
can set a ``Timeout`` option on your ``Client`` and the operation will
41+
derive the timeout specification from this setting. To learn more
42+
about using the single timeout setting, see the :ref:`Connection Guide <golang-timeout-setting>`.
3843

3944
Expiration
4045
----------

0 commit comments

Comments
 (0)