Docs Menu
Docs Home
/ / /
Rust Driver
/ /

Connection Options

In this guide, you can learn about MongoDB connection and authentication options. You can set connection options as parameters of your connection string to specify how your Client instance behaves while connected to the server.

Option Name
Accepted Values
Default Value
Description
appName
String
None
Specifies the application name that the Client instance sends to the server as part of the handshake.
Specifying an appName can help you use the server logs to determine which Client instance is connected to the server.
authMechanism
String
None
Specifies which authentication mechanism to use. If you do not specify this option, the driver uses the default authentication mechanism. To learn more about authentication in the Rust driver, see the guide on Authentication Mechanisms.
authMechanismProperties
String
None
Specifies more properties for the authentication mechanism set in the authMechanism option.
authSource
String
See description
Specifies the database used to authenticate.
This option defaults to admin for SCRAM-based authentication mechanisms, $external for the MONGODB-X509 mechanism, and the database name or $external for the PLAIN mechanism.
compressors
A comma-separated list of strings
None
Specifies compressors that the Client instance uses in the specified order. To learn more about network compression, see the Network Compression guide.
connectTimeoutMS
Non-negative integer
10000 (10 seconds)
Specifies the connection timeout, in milliseconds, passed to each underlying TCP stream when attempting to connect to the server.
directConnection
Boolean
false
Specifies whether the Client instance directly connects to a single host instead of discovering and connecting to all servers in the cluster.
heartbeatFrequencyMS
Integer greater than or equal to 500
10000 (10 seconds)
Specifies the amount of time in milliseconds that each monitoring thread waits between performing server checks.
journal
Boolean
false
Requests acknowledgment that the operation propagated to the on-disk journal.
localThresholdMS
Non-negative integer
15
Specifies the amount of time in milliseconds that the average round-trip time between the driver and server can last compared to the shortest round-trip time of all the suitable servers.
A value of 0 indicates that there is no latency window, so only the server with the lowest average round-trip time is eligible.
maxIdleTimeMS
Non-negative integer
0
Specifies the amount of time in milliseconds that a connection can remain idle in a connection pool the server closes it.
A value of 0 indicates that the client does not close idle connections.
maxStalenessSeconds
-1, or any integer greater than or equal to 90
-1
Specifies the maximum lag, in seconds, behind the primary node that a secondary node can be to be considered for the given operation.
The value of this option must be at least 90, or the operation raises an error. A value of -1 means there is no maximum lag.
maxPoolSize
Non-negative integer
10
Specifies the maximum number of connections that the Client instance can create in a connection pool for a given server.
If you attempt an operation while the value of maxPoolSize connections are checked out, the operation waits until an in-progress operation finishes and the connection returns to the pool.
minPoolSize
Non-negative integer
0
Specifies the minimum number of connections that are available in a server's connection pool at a given time.
If fewer than minPoolSize connections are in the pool, the server adds connections in the background up to the value of minPoolSize.
readConcernLevel
String
None
Specifies the default read concern for operations performed on the Client instance. To learn more, see Read Concern in the Server manual.
readPreference
String
primary
Specifies how the driver routes a read operation to members of a replica set. To learn more, see Read Preference in the Server manual.
readPreferenceTags
A list of comma-separated key-value pairs
None
Specifies which replica set members are considered for operations. Each instance of this key is a separate tag set. The driver checks each tag set until it finds one or more servers with each tag in the set.
replicaSet
String
None
Specifies the name of the replica set that the Client instance connects to.
retryReads
Boolean
true
Specifies whether the client retries a read operation if the operation fails.
serverSelectionTimeoutMS
Non-negative integer
30000 (30 seconds)
Specifies the amount of time in milliseconds that the Client instance waits when attempting to select a server for an operation before timing out.
tls
Boolean
false
Specifies the TLS configuration for the Client instance to use in its connections with the server. By default, TLS is off.
tlsAllowInvalidCertificates
Boolean
false
Specifies whether the Client instance returns an error if the server presents an invalid certificate.
We recommend that you set this option to true only in testing environments to avoid creating vulnerabilities in your application.
tlsCAFile
String
See description
Specifies the path to the certificate authority (CA) file that the Client instance uses for TLS.
If you do not specify this option, the driver uses the Mozilla root certificates from the webpki-roots crate.
tlsCertificateKeyFile
String
None
Specifies the path to the certificate file that the Client instance presents to the server to verify its identify.
If you do not set this option, the Client instance does not attempt to verify its identity to the server.
tlsInsecure
Boolean
false
Specifies whether the Client instance returns an error if the server presents an invalid certificate.
We recommend that you set this option to true only in testing environments to avoid creating vulnerabilities in your application.
w
Non-negative integer or string
None
Requests acknowledgment that the operation has propagated to a specific number or variety of servers.
To learn more, see Write Concern in the Server manual.
wTimeoutMS
Non-negative integer
No timeout
Specifies a time limit, in milliseconds, for the write concern. If an operation has not propagated to the requested level within the time limit, the driver raises an error.
zlibCompressionLevel
Integer between -1 and 9 (inclusive)
-1
Specifies the level field of the zlib compression if you use that compressor.
Setting a value of -1 selects the default compression level (6).
Setting a value of 0 specifies no compression, and setting a value of 9 specifies maximum compression.
To learn more about network compression, see the Network Compression guide.

To see a full list of connection options, visit the Connection String Options section of the Server manual entry on Connection Strings.

Back

Connection Guide