Overview
This guide explains several common MongoDB connection and authentication options. You can pass the connection options as parameters in the connection URI to specify the behavior of the client.
Options
The following table describes the connection options that you can set in your connection URI. Each entry provides the option name, value type, default value, and a description of the option.
Option Name | Type | Default Value | Description |
---|---|---|---|
timeoutMS | integer |
| Specifies the number of milliseconds that a single operation run on the
|
connectTimeoutMS | integer |
| Specifies the time in milliseconds to attempt a connection before timing out. |
maxPoolSize | integer |
| Specifies the maximum number of connections that a connection pool may have at a given time. |
replicaSet | string |
| Specifies the replica set name for the cluster. All nodes in the replica set must have the same replica set name, or the Client will not consider them as part of the set. |
maxIdleTimeMS | integer |
| Specifies the maximum amount of time a connection can remain idle
in the connection pool before being removed and closed. The
default is |
minPoolSize | integer |
| Specifies the minimum number of connections that the driver maintains in a single connection pool. |
serverSelectionTimeoutMS | integer |
| Specifies the number of milliseconds to wait to find an available, suitable server to execute an operation. |
heartbeatFrequencyMS | integer |
| Specifies the number of milliseconds to wait between periodic background server checks. |
tls | boolean |
| Specifies whether to establish a Transport Layer Security (TLS)
connection with the instance. This is automatically set to |
w | string or integer |
| Specifies the write concern. To learn more about values, see the server documentation on Write Concern options. |
directConnection | boolean |
| Specifies whether to force dispatch all operations to the host specified in the connection URI. |
For a full list of connection options, see the ClientOptions API documentation.