@@ -68,7 +68,7 @@ your MongoDB instance.
6868The last part of the connection string specifies connection and authentication
6969options. In the example, we set two connection options:
7070``maxPoolSize=20`` and ``w=majority``. To learn more about connection
71- options, read the :ref:`golang-connection-options` section of this guide.
71+ options, see the :ref:`golang-connection-options` guide.
7272
7373Connection Example
7474~~~~~~~~~~~~~~~~~~
@@ -172,169 +172,12 @@ When connecting to a replica set, the driver takes the following actions by defa
172172Direct Connection
173173`````````````````
174174
175- To force operations on the host designated in the connection URI, specify the ``directConnection`` option. Direct
176- connections:
177-
178- - Don't support SRV strings.
179- - Fail on writes when the specified host is not the **primary**.
180- - Require you to :manual:`specify a secondary read preference </core/read-preference/#mongodb-readmode-secondary>`
181- when the specified host isn't the **primary**.
182-
183- .. _golang-connection-options:
184-
185- ------------------
186- Connection Options
187- ------------------
188-
189- This section explains several common MongoDB connection and authentication
190- options. You can pass the connection options as parameters of the connection
191- URI to specify the behavior of the client.
192-
193- .. list-table::
194- :header-rows: 1
195- :widths: 34 10 12 44
196-
197- * - Option Name
198- - Type
199- - Default Value
200- - Description
201-
202- * - **timeoutMS**
203- - integer
204- - ``null``
205- - Specifies the number of milliseconds that a single operation run on the
206- ``Client`` can take before returning a timeout error. Operations honor
207- this setting only if there is no deadline on the operation Context.
208-
209- * - **connectTimeoutMS**
210- - integer
211- - ``30000``
212- - Specifies the number of milliseconds to wait before timeout on a TCP
213- connection.
214-
215- * - **maxPoolSize**
216- - integer
217- - ``100``
218- - Specifies the maximum number of connections that a connection pool may
219- have at a given time.
220-
221- * - **replicaSet**
222- - string
223- - ``null``
224- - Specifies the replica set name for the cluster. All nodes in the
225- replica set must have the same replica set name, or the Client will not
226- consider them as part of the set.
227-
228- * - **maxIdleTimeMS**
229- - integer
230- - ``0``
231- - Specifies the maximum amount of time a connection can remain idle
232- in the connection pool before being removed and closed. The
233- default is ``0``, meaning a connection can remain unused
234- indefinitely.
235-
236- * - **minPoolSize**
237- - integer
238- - ``0``
239- - Specifies the minimum number of connections that the driver maintains
240- in a single connection pool.
241-
242- * - **socketTimeoutMS**
243- - integer
244- - ``0``
245- - Specifies the number of milliseconds to wait for a socket read or
246- write to return before returning a network error. The ``0``
247- default value indicates that there is no timeout.
248-
249- * - **serverSelectionTimeoutMS**
250- - integer
251- - ``30000``
252- - Specifies the number of milliseconds to wait to find an available,
253- suitable server to execute an operation.
254-
255- * - **heartbeatFrequencyMS**
256- - integer
257- - ``10000``
258- - Specifies the number of milliseconds to wait between periodic
259- background server checks.
260-
261- * - **tls**
262- - boolean
263- - ``false``
264- - Specifies whether to establish a Transport Layer Security (TLS)
265- connection with the instance. This is automatically set to ``true``
266- when using a DNS seedlist (SRV) in the connection string. You can
267- override this behavior by setting the value to ``false``.
268-
269- * - **w**
270- - string or integer
271- - ``null``
272- - Specifies the write concern. To learn more about values, see the
273- server documentation on
274- :manual:`Write Concern options </reference/write-concern>`.
275-
276- * - **directConnection**
277- - boolean
278- - ``false``
279- - Specifies whether to force dispatch **all** operations to the host
280- specified in the connection URI.
281-
282- For a full list of connection options, see the `ClientOptions API
283- documentation
284- <{+api+}/mongo/options#ClientOptions>`__.
285-
286- .. _golang-timeout-setting:
287-
288- Single Timeout Setting
289- ~~~~~~~~~~~~~~~~~~~~~~
290-
291- You can set a single ``Timeout`` option on your ``Client`` to govern the
292- amount of time that a single operation can take to execute using the
293- ``SetTimeout()`` method or specifying the ``timeoutMS`` option in your
294- connection URI string. ``Database``, ``Collection``,
295- ``Session``, ``ChangeStream``, and ``Bucket`` instances elsewhere in
296- your code inherit the ``Timeout`` option from ``Client`` if you do not set a
297- Context for operations against the same entity.
298-
299- If you pass a Context into an operation with a deadline, the driver uses
300- that Context deadline for the operation. If the context does not have a
301- deadline, the driver derives a new Context from the given Context using
302- the ``Timeout`` option set on the ``Client``.
303-
304- .. note:: Retries under Timeout Specification
305-
306- With default settings, if you set a ``Timeout`` option on your ``Client``
307- and your operation requires a retry, the driver retries the operation
308- as many times as possible before the timeout expires. Once the timeout
309- expires, the driver returns a timeout error. Versions 1.1 and later
310- of the {+driver-short+} enable retryable reads and writes by default.
311- See the Server manual for more information about :ref:`retryable
312- reads <retryable-reads>` and :manual:`retryable writes </core/retryable-writes/>`.
313-
314- The following code shows how to set the ``Timeout`` option on a ``Client``
315- with the ``SetTimeout`` option:
316-
317- .. code-block:: go
318-
319- opts := options.Client().SetTimeout(5 * time.Second)
320-
321- The following example shows how you can set a single timeout with the
322- URI option and execute an operation that inherits this setting:
323-
324- .. code-block:: go
325-
326- uri := "mongodb://user:pass@sample.host:27017/?timeoutMS=5000"
327-
328- client, err := mongo.Connect(options.Client().ApplyURI(uri))
329- coll := client.Database("<db>").Collection("<collection>")
330-
331- ...
332- coll.InsertOne(context.Background(), doc)
333-
334- .. important:: Legacy Timeout Options
335-
336- ``SocketTimeout``, ``wTimeout``, ``MaxTime``, and ``MaxCommitTime``
337- will be deprecated in an upcoming release. The driver ignores ``MaxTime`` and
338- ``MaxCommitTime`` if you set ``Timeout``. The driver still honors
339- ``SocketTimeout`` and ``wTimeout``, but these settings may result in
340- undefined behavior. Consider using only the single timeout option instead.
175+ To force operations on the host designated in the connection URI,
176+ specify the ``directConnection`` option. Direct connections exhibit the
177+ following behavior:
178+
179+ - They don't support SRV strings.
180+ - They fail on writes when the specified host is not the **primary**.
181+ - They require you to specify a :manual:`secondary read preference
182+ </core/read-preference/#mongodb-readmode-secondary>` when the
183+ specified host isn't the **primary** node.
0 commit comments