Skip to content

Commit 26eff61

Browse files
authored
DOCSP-26186: maxTimeMS explanation (#465)
* DOCSP-26186: specify that maxTimeMS applies to operations only * first pass fixes * DB suggestion
1 parent a8d7040 commit 26eff61

File tree

1 file changed

+22
-26
lines changed

1 file changed

+22
-26
lines changed

source/faq.txt

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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

7680
To specify the optional settings for your ``MongoClient``, declare one or
7781
more 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>`__
8993
API 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+
91102
How 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

170181
You 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

188185
The following example shows how you can chain the ``maxTimeMS()`` method
189186
to an operation that returns a ``Cursor``:
@@ -309,7 +306,6 @@ to reach ``server1``, ``server2``, and ``server3``.
309306
]
310307
}
311308

312-
313309
If you are unable to find the answer to your question here, try our forums and
314310
support channels listed in the :doc:`Issues and Help <issues-and-help>`
315311
section.

0 commit comments

Comments
 (0)