@@ -36,13 +36,25 @@ What Is the Difference Between "connectTimeoutMS", "socketTimeoutMS" and "maxTim
3636 after it has reached the server. If an operation runs over the
3737 specified time limit, it returns a timeout error.
3838
39+ To specify the optional settings for your ``MongoClient``, declare one or
40+ more of them in the ``options`` object of the constructor as follows:
41+
42+ .. code-block:: javascript
43+
44+ const client = new MongoClient(uri, {
45+ connectTimeoutMS: <integer value>,
46+ socketTimeoutMS: <integer value>,
47+ maxTimeMS: <integer value>,
48+ });
49+
50+
3951How Can I Prevent the Driver From Hanging During Connection or From Spending Too Long Trying to Reach Unreachable Replica Sets?
4052-------------------------------------------------------------------------------------------------------------------------------
4153
4254To prevent the driver from hanging during connection or to prevent the
4355driver from spending too long trying to reach unreachable replica sets,
4456you can set the ``connectTimeoutMS`` option of your
45- :doc:`connection options </fundamentals/connection#connection-options>`.
57+ :doc:`connection options </fundamentals/connection#connection-options>`.
4658Generally, you should ensure that the
4759``connectTimeoutMS`` setting is not lower than the longest network
4860latency you have to a member of the set. If one of the secondary members
@@ -80,6 +92,7 @@ through the driver.
8092
8193How Can I Prevent Sockets From Timing out Before They Become Active?
8294--------------------------------------------------------------------
95+
8396Having a large connection pool does not always reduce reconnection
8497requests. Consider the following example:
8598
@@ -94,25 +107,49 @@ One message every 3000 milliseconds is not enough to keep the sockets
94107active, so several of the sockets will time out after 5000 milliseconds.
95108Reduce the ``poolSize`` in the connection settings to fix the problem.
96109
110+ To specify the optional ``poolSize`` setting for your ``MongoClient``, declare
111+ it in the ``options`` object of the constructor as follows:
112+
113+ .. code-block:: javascript
114+
115+ const client = new MongoClient(uri, {
116+ poolSize: <integer value>,
117+ });
118+
119+
97120What Does a Value of "0" mean for "connectTimeoutMS" and "socketTimeoutMS"?
98121---------------------------------------------------------------------------
99122
100- Setting ``connectTimeoutMS`` and ``socketTimeoutMS`` to the value ``0`` has
101- causes the application to use the operating system's default socket timeout value.
123+ If you set the value of ``connectTimeoutMS`` or ``socketTimeoutMS`` to
124+ ``0``, your application will use the operating system's default socket
125+ timeout value.
102126
103127How Can I Prevent Long-Running Operations From Slowing Down the Server?
104128-----------------------------------------------------------------------
105129
106- By using ``maxTimeMS()`` you can prevent long-running operations from
107- slowing down the server. This method allows the MongoDB server to cancel
108- operations that run for more than the set value of ``maxTimeMS``.
130+ You can prevent long-running operations from slowing down the server by
131+ specifying a timeout value. You can use the ``maxTimeMS`` option setting in
132+ your ``MongoClient`` constructor to apply this to all the operations
133+ called by the client, or chain the ``maxTimeMS()`` method to an operation that
134+ returns a ``Cursor`` to apply to that specific one.
135+
136+ To specify the optional ``maxTimeMS`` setting for your ``MongoClient``,
137+ declare it in the ``options`` object of the constructor as follows:
138+
139+ .. code-block:: javascript
109140
110- The following example demonstrates how to use MaxTimeMS with a find
111- operation:
141+ const client = new MongoClient(uri, {
142+ connectTimeoutMS: <integer value>,
143+ socketTimeoutMS: <integer value>,
144+ maxTimeMS: <integer value>,
145+ });
146+
147+
148+ The following example shows how you can chain the ``maxTimeMS()`` method
149+ to an operation that returns a ``Cursor``:
112150
113151.. literalinclude:: /code-snippets/faq/maxTimeMS-example.js
114152 :language: javascript
115- :linenos:
116153
117154What Does the "keepAlive" Setting Do?
118155---------------------------------------
@@ -185,6 +222,21 @@ other, faster operations.
185222 If the number of operations is greater than the set ``poolSize`` and
186223 a slow operation occurs, subsequent operations will be delayed.
187224
225+
226+ To create a separate connection pool, instantiate another ``MongoClient``
227+ call the ``connect()`` method on it. See the following example for the
228+ syntax you can use to create two clients, each with its own connection
229+ pool:
230+
231+ .. code-block:: javascript
232+
233+ const clientA = new MongoClient(uri, options);
234+ clientA.connect(); // any method calls on clientA use clientA's connection pool
235+
236+ const clientB = new MongoClient(uri, options);
237+ clientB.connect(); // any method calls on clientB use clientB's connection pool
238+
239+
188240How Can I Ensure My Connection String Is Valid for a Replica Set?
189241-----------------------------------------------------------------
190242
@@ -216,3 +268,8 @@ to reach ``server1``, ``server2``, and ``server3``.
216268 }
217269 ]
218270 }
271+
272+
273+ If you are unable to find the answer to your question here, try our forums and
274+ support channels listed in the :doc:`Issues and Help <issues-and-help>`
275+ section.
0 commit comments