连接选项
Overview
在本指南中,您可以了解 MongoDB 连接和身份验证选项。 您可以将连接选项设置为连接字符串的参数,以指定 Client
实例在连接到服务器时的行为方式。
选项名称 | 接受的值 | 默认值 | 说明 |
---|---|---|---|
appName | 字符串 | 无 | 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 | 字符串 | 无 | 指定要使用的身份验证机制。 如果不指定此选项,驾驶员将使用默认的身份验证机制。 要学习;了解有关Rust驾驶员中身份验证的详情,请参阅身份验证机制指南。 |
authMechanismProperties | 字符串 | 无 | 为 |
authSource | 字符串 | 查看说明 | 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 | 以逗号分隔的字符串列表 | 无 | 指定 |
connectTimeoutMS | Non-negative integer |
| 指定尝试连接到服务器时传递给每个底层 TCP 流的连接超时时间(以毫秒为单位)。 |
directConnection | 布尔 |
| 指定 |
heartbeatFrequencyMS | 大于或等于 500 的整数。 |
| 指定每个监控线程在执行服务器检查之间等待的时间(以毫秒为单位)。 |
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 |
|
| 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 |
| 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 |
| 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 | 字符串 | 无 | |
readPreference | 字符串 |
| |
readPreferenceTags | 以逗号分隔的键值对列表 | 无 | 指定考虑对哪些副本集成员进行操作。 此键的每个实例都是一个单独的标签集。 驱动程序会检查每个标签集,直到找到具有标签集中每个标签的一台或多台服务器。 |
replicaSet | 字符串 | 无 | 指定 |
retryReads | 布尔 |
| 指定在操作失败时客户端是否重试读取操作。 |
serverSelectionTimeoutMS | Non-negative integer |
| 指定 |
TLS | 布尔 |
| 指定 |
tlsAllowInvalidCertificates | 布尔 |
| 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 | 字符串 | 查看说明 | 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 | 字符串 | 无 | 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 | 布尔 |
| 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 | 非负整数或字符串 | 无 | 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 | 无超时 | 指定写关注(write concern)的时间限制(以毫秒为单位)。如果操作未在时限内传播到请求的级别,驱动程序将引发错误。 |
zlibCompressionLevel | -1 到 9(含)之间的整数 |
| 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. |
要查看连接选项的完整列表,请访问 stringMongoDB Server手册中有关连接字符串的条目的 连接 选项部分 。