@@ -143,6 +143,13 @@ URI to specify the behavior of the client.
143
143
- Default Value
144
144
- Description
145
145
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
+
146
153
* - **connectTimeoutMS**
147
154
- integer
148
155
- ``30000``
@@ -219,3 +226,47 @@ URI to specify the behavior of the client.
219
226
For a full list of connection options, see the `ClientOptions API
220
227
documentation
221
228
<{+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.
0 commit comments