@@ -51,9 +51,11 @@ What Is the Difference Between "connectTimeoutMS", "socketTimeoutMS" and "maxTim
5151
5252 * - Setting
5353 - Description
54- * - connectTimeoutMS
55- - ``connectTimeoutMS`` is a :ref:`connection option <node-connection-options>` that sets the time, in milliseconds,
56- for an individual connection from your connection pool to establish a TCP connection to the MongoDB server before
54+ * - **connectTimeoutMS**
55+ - ``connectTimeoutMS`` is a :ref:`connection option
56+ <node-connection-options>` that sets the time, in milliseconds,
57+ for an individual connection from your connection pool to
58+ establish a TCP connection to the MongoDB server before
5759 timing out.
5860
5961 .. tip::
@@ -62,16 +64,18 @@ What Is the Difference Between "connectTimeoutMS", "socketTimeoutMS" and "maxTim
6264 connection to a MongoDB server, use the ``serverSelectionTimeoutMS`` option instead.
6365
6466 **Default:** 10000
65- * - socketTimeoutMS
67+ * - ** socketTimeoutMS**
6668 - ``socketTimeoutMS`` specifies the amount of time the driver waits
6769 for an inactive socket before closing it. The default value is to
6870 never time out the socket. This option applies only to sockets that
6971 have already been connected.
70- * - maxTimeMS
71- - `maxTimeMS <{+api+}/classes/FindCursor.html#maxTimeMS>`__ is the maximum
72- amount of time the server should wait for an operation to complete
73- after it has reached the server. If an operation runs over the
74- specified time limit, it returns a timeout error.
72+ * - **maxTimeMS**
73+ - `maxTimeMS <{+api+}/classes/FindCursor.html#maxTimeMS>`__
74+ specifies the maximum amount of time the server
75+ should wait for an operation to complete after it has reached the
76+ server. If an operation runs over the specified time limit, it
77+ returns a timeout error. You can pass ``maxTimeMS`` only to an
78+ individual operation or to a cursor.
7579
7680To specify the optional settings for your ``MongoClient``, declare one or
7781more available settings in the ``options`` object of the constructor as
@@ -88,6 +92,13 @@ To see all the available settings, see the
8892`MongoClientOptions <{+api+}/interfaces/MongoClientOptions.html>`__
8993API Documentation.
9094
95+ To specify ``maxTimeMS``, chain the ``maxTimeMS()`` method with a
96+ timeout specification to an operation that returns a ``Cursor``:
97+
98+ .. code-block:: javascript
99+
100+ const cursor = collection.find({}).maxTimeMS(50);
101+
91102How Can I Prevent the Driver From Hanging During Connection or From Spending Too Long Trying to Reach Unreachable Replica Sets?
92103-------------------------------------------------------------------------------------------------------------------------------
93104
@@ -168,22 +179,8 @@ How Can I Prevent Long-Running Operations From Slowing Down the Server?
168179-----------------------------------------------------------------------
169180
170181You can prevent long-running operations from slowing down the server by
171- specifying a timeout value. You can use the ``maxTimeMS`` option setting in
172- your ``MongoClient`` constructor to apply this to all the operations
173- called by the client, or chain the ``maxTimeMS()`` method to an operation that
174- returns a ``Cursor`` to apply to that specific one.
175-
176- To specify the optional ``maxTimeMS`` setting for your ``MongoClient``,
177- declare it in the ``options`` object of the constructor as follows:
178-
179- .. code-block:: javascript
180-
181- const client = new MongoClient(uri, {
182- connectTimeoutMS: <integer value>,
183- socketTimeoutMS: <integer value>,
184- maxTimeMS: <integer value>,
185- });
186-
182+ specifying a timeout value. You can chain the ``maxTimeMS()`` method to
183+ an operation that returns a ``Cursor`` to set a timeout on a specific action.
187184
188185The following example shows how you can chain the ``maxTimeMS()`` method
189186to an operation that returns a ``Cursor``:
@@ -309,7 +306,6 @@ to reach ``server1``, ``server2``, and ``server3``.
309306 ]
310307 }
311308
312-
313309If you are unable to find the answer to your question here, try our forums and
314310support channels listed in the :doc:`Issues and Help <issues-and-help>`
315311section.
0 commit comments