|
| 1 | +.. _golang-connection-options: |
| 2 | + |
| 3 | +========================== |
| 4 | +Specify Connection Options |
| 5 | +========================== |
| 6 | + |
| 7 | +.. facet:: |
| 8 | + :name: genre |
| 9 | + :values: reference |
| 10 | + |
| 11 | +.. meta:: |
| 12 | + :keywords: code example, timeout, customize connection |
| 13 | + |
| 14 | +.. contents:: On this page |
| 15 | + :local: |
| 16 | + :backlinks: none |
| 17 | + :depth: 2 |
| 18 | + :class: singlecol |
| 19 | + |
| 20 | +.. toctree:: |
| 21 | + :titlesonly: |
| 22 | + :maxdepth: 1 |
| 23 | + |
| 24 | + Specify Connection Options <connect/connection-options/specify-connection-options> |
| 25 | + Compress Network Traffic <connect/connection-options/network-compression> |
| 26 | + Customize Cluster Settings <connect/connection-options/cluster-settings> |
| 27 | + Stable API <connect/connection-options/stable-api> |
| 28 | + Limit Server Execution Time <connect/connection-options/csot> |
| 29 | + Connection Pools <connect/connection-options/connection-pools> |
| 30 | + |
| 31 | +Overview |
| 32 | +-------- |
| 33 | + |
| 34 | +This guide explains several common MongoDB connection and authentication |
| 35 | +options. You can pass the connection options as parameters in the connection |
| 36 | +URI to specify the behavior of the client. |
| 37 | + |
| 38 | +Options |
| 39 | +------- |
| 40 | + |
| 41 | +The following table describes the connection options that you can set in |
| 42 | +your connection URI. Each entry provides the option name, value type, |
| 43 | +default value, and a description of the option. |
| 44 | + |
| 45 | +.. list-table:: |
| 46 | + :header-rows: 1 |
| 47 | + :widths: 34 10 12 44 |
| 48 | + |
| 49 | + * - Option Name |
| 50 | + - Type |
| 51 | + - Default Value |
| 52 | + - Description |
| 53 | + |
| 54 | + * - **timeoutMS** |
| 55 | + - integer |
| 56 | + - ``null`` |
| 57 | + - Specifies the number of milliseconds that a single operation run on the |
| 58 | + ``Client`` can take before returning a timeout error. Operations honor |
| 59 | + this setting only if there is no deadline on the operation |
| 60 | + Context. To learn more about this option, see the :ref:`CSOT |
| 61 | + <golang-csot>` guide. |
| 62 | + |
| 63 | + * - **connectTimeoutMS** |
| 64 | + - integer |
| 65 | + - ``30000`` |
| 66 | + - Specifies the time in milliseconds to attempt a connection before |
| 67 | + timing out. |
| 68 | + |
| 69 | + * - **maxPoolSize** |
| 70 | + - integer |
| 71 | + - ``100`` |
| 72 | + - Specifies the maximum number of connections that a connection pool may |
| 73 | + have at a given time. |
| 74 | + |
| 75 | + * - **replicaSet** |
| 76 | + - string |
| 77 | + - ``null`` |
| 78 | + - Specifies the replica set name for the cluster. All nodes in the |
| 79 | + replica set must have the same replica set name, or the Client will not |
| 80 | + consider them as part of the set. |
| 81 | + |
| 82 | + * - **maxIdleTimeMS** |
| 83 | + - integer |
| 84 | + - ``0`` |
| 85 | + - Specifies the maximum amount of time a connection can remain idle |
| 86 | + in the connection pool before being removed and closed. The |
| 87 | + default is ``0``, meaning a connection can remain unused |
| 88 | + indefinitely. |
| 89 | + |
| 90 | + * - **minPoolSize** |
| 91 | + - integer |
| 92 | + - ``0`` |
| 93 | + - Specifies the minimum number of connections that the driver maintains |
| 94 | + in a single connection pool. |
| 95 | + |
| 96 | + * - **serverSelectionTimeoutMS** |
| 97 | + - integer |
| 98 | + - ``30000`` |
| 99 | + - Specifies the number of milliseconds to wait to find an available, |
| 100 | + suitable server to execute an operation. |
| 101 | + |
| 102 | + * - **heartbeatFrequencyMS** |
| 103 | + - integer |
| 104 | + - ``10000`` |
| 105 | + - Specifies the number of milliseconds to wait between periodic |
| 106 | + background server checks. |
| 107 | + |
| 108 | + * - **tls** |
| 109 | + - boolean |
| 110 | + - ``false`` |
| 111 | + - Specifies whether to establish a Transport Layer Security (TLS) |
| 112 | + connection with the instance. This is automatically set to ``true`` |
| 113 | + when using a DNS seedlist (SRV) in the connection string. You can |
| 114 | + override this behavior by setting the value to ``false``. |
| 115 | + |
| 116 | + * - **w** |
| 117 | + - string or integer |
| 118 | + - ``null`` |
| 119 | + - Specifies the write concern. To learn more about values, see the |
| 120 | + server documentation on |
| 121 | + :manual:`Write Concern options </reference/write-concern>`. |
| 122 | + |
| 123 | + * - **directConnection** |
| 124 | + - boolean |
| 125 | + - ``false`` |
| 126 | + - Specifies whether to force dispatch **all** operations to the host |
| 127 | + specified in the connection URI. |
| 128 | + |
| 129 | +For a full list of connection options, see the `ClientOptions API |
| 130 | +documentation |
| 131 | +<{+api+}/mongo/options#ClientOptions>`__. |
0 commit comments