Docs Home → Develop Applications → MongoDB Drivers → Node.js
Connection Options
This version of the documentation is archived and no longer supported. View the current documentation to learn how to upgrade your version of the MongoDB Node.js driver.
This section explains the MongoDB connection and authentication options supported by the driver. You can pass the connection options as parameters of the connection URI to specify the behavior of the client.
Option Name | Type | Default Value | Description |
---|---|---|---|
connectTimeoutMS | integer | 30000 | Specifies the number of milliseconds to wait before timeout on a TCP
connection. |
directConnection | boolean | false | Specifies whether to force dispatch all operations to the host
specified in the connection URI. |
family | number | null | Specifies the version of the Internet Protocol (IP). The valid values
are: 4 , 6 , 0 , or null . The 0 and null settings
attempt to connect with IPv6 and fall back to IPv4 upon failure. |
forceServerObjectId | boolean | false | Specifies whether to force the server to assign _id values to
documents instead of the driver. |
ignoreUndefined | boolean | false | Specifies whether the BSON serializer should ignore undefined fields. |
keepAlive | boolean | true | Specifies whether to enable keepAlive on the TCP socket. For more
information, see the documentation for Node.js socket.setKeepAlive. |
keepAliveInitialDelay | integer | 120000 | Specifies the number of milliseconds to wait before initiating
keepAlive on the TCP socket. For more information, see the
documentation for Node.js socket.setKeepAlive. |
logger | object | null | Specifies a custom logger for the client to use. |
loggerLevel | string | null | Specifies the logger level used by the driver. Valid choices are:
error , warn , info , and debug . |
maxPoolSize | integer | 100 | Specifies the maximum number of connections that a connection pool may
have at a given time. |
maxIdleTimeMS | integer | ∞ | Specifies the maximum amount of time a connection can remain idle in the
connection pool before being removed and closed. |
minPoolSize | integer | 0 | Specifies the minimum number of connections that must exist at any moment
in a single connection pool. |
noDelay | boolean | true | Specifies whether to use the TCP socket no-delay option. For more
information, see the documentation for Node.js socket.setNoDelay. |
pkFactory | object | null | Specifies a primary key factory object that generates custom _id
keys. |
promiseLibrary | object | null | Specifies the Promise library class the application uses (e.g. Bluebird).
This library must be compatible with ES6. |
promoteBuffers | boolean | false | Specifies whether to promote Binary BSON values to native Node.js
Buffer type data. |
promoteLongs | boolean | true | Specifies whether to convert Long values to a number if they fit
inside 53 bits of resolution. |
promoteValues | boolean | true | Specifies whether to promote BSON values to Node.js native types when
possible. When set to false, it uses wrapper types to present
BSON values. |
raw | boolean | false | Specifies whether to return document results as raw BSON buffers. |
serializeFunctions | boolean | false | Specifies whether to serialize functions on any object passed to the
server. |
serverApi | string or enum | null | Specifies the API version that operations must conform to. See the
MongoDB manual entry on Stable API
for more information. |
srvMaxHosts | integer | 0 | Sets the maximum number of hosts the driver can connect to when using the DNS seedlist (SRV) connection protocol, identified by the mongodb+srv connection string prefix. When set to 0 , thedriver does not limit the number of hosts. Throws an exception if the value is not equal to 0 and you are
not using the SRV connection protocol. |
srvServiceName | string | mongodb | Specifies the SRV record service name to which the driver should
connect. |
socketTimeoutMS | integer | 360000 | Specifies the number of milliseconds to wait before timeout on a TCP
socket. |
tls | boolean | false | Specifies whether to establish a Transport Layer Security (TLS)
connection with the instance. This is automatically set to true
when using a DNS seedlist (SRV) in the connection string. You can
override this behavior by setting the value to false . |
validateOptions | boolean | false | Specifies whether to error when the method parameters contain an
unknown or incorrect option. If false , the driver produces warnings
only. |
waitQueueTimeoutMS | integer | 0 | Specifies the maximum amount of time in milliseconds that operation
execution can wait for a connection to become available. |
writeConcern | string or integer | null | Specifies the write concern. For more information on values, see the
server documentation on the
w Option. |
For a complete list of options, see the MongoClient API reference page.