Interface MongoOptions

Parsed Mongo Client Options.

User supplied options are documented by MongoClientOptions.用户提供的选项由MongoClientOptions记录。

NOTE: The client's options parsing is subject to change to support new features.客户端的选项解析可能会更改以支持新功能。 This type is provided to aid with inspection of options after parsing, it should not be relied upon programmatically.提供此类型是为了帮助在解析后检查选项,不应以编程方式依赖它。

Options are sourced from:选项来源于:

  • connection string连接字符串
  • options object passed to the MongoClient constructor传递给MongoClient构造函数的options对象
  • file system (ex. tls settings)文件系统(例如tls设置)
  • environment variables环境变量
  • DNS SRV records and TXT recordsDNS SRV记录和TXT记录

Not all options may be present after client construction as some are obtained from asynchronous operations.并非所有选项都可以在客户端构建后出现,因为有些选项是从异步操作中获得的。

Hierarchy

  • Required<Pick<MongoClientOptions, "autoEncryption" | "connectTimeoutMS" | "directConnection" | "driverInfo" | "forceServerObjectId" | "minHeartbeatFrequencyMS" | "heartbeatFrequencyMS" | "localThresholdMS" | "maxConnecting" | "maxIdleTimeMS" | "maxPoolSize" | "minPoolSize" | "monitorCommands" | "noDelay" | "pkFactory" | "raw" | "replicaSet" | "retryReads" | "retryWrites" | "serverSelectionTimeoutMS" | "socketTimeoutMS" | "srvMaxHosts" | "srvServiceName" | "tlsAllowInvalidCertificates" | "tlsAllowInvalidHostnames" | "tlsInsecure" | "waitQueueTimeoutMS" | "zlibCompressionLevel">>
  • SupportedNodeConnectionOptions
    • MongoOptions

Indexable

[featureFlag: symbol]: any

Properties

ALPNProtocols?: string[] | Uint8Array | Uint8Array[]

An array of strings or a Buffer naming possible ALPN protocols.字符串数组或缓冲区,命名可能的ALPN协议。 (Protocols should be ordered by their priority.)(协议应按优先级排序。)

appName?: string
autoEncryption: AutoEncryptionOptions

Optionally enable in-use auto encryption可选地启用使用中的自动加密

Remarks

Automatic encryption is an enterprise only feature that only applies to operations on a collection. 自动加密是企业独有的功能,仅适用于集合上的操作。Automatic encryption is not supported for operations on a database or view, and operations that are not bypassed will result in error (see libmongocrypt: Auto Encryption Allow-List). To bypass automatic encryption for all operations, set bypassAutoEncryption=true in AutoEncryptionOpts.数据库或视图上的操作不支持自动加密,未绕过的操作将导致错误(请参阅libmongocrypt:自动加密允许列表)。要绕过所有操作的自动加密,请在AutoEncryptionOpts中设置bypassAutoEncryption=true

Automatic encryption requires the authenticated user to have the listCollections privilege action.自动加密要求经过身份验证的用户具有listCollections权限操作

If a MongoClient with a limited connection pool size (i.e a non-zero maxPoolSize) is configured with AutoEncryptionOptions, a separate internal MongoClient is created if any of the following are true:如果使用AutoEncryptionOptions配置了连接池大小有限(即maxPoolSize为非零)的MongoClient,则如果以下任何一项为真,则会创建一个单独的内部MongoClient:

  • AutoEncryptionOptions.keyVaultClient is not passed.未传入。
  • AutoEncryptionOptions.bypassAutomaticEncryption is false.false

If an internal MongoClient is created, it is configured with the same options as the parent MongoClient except minPoolSize is set to 0 and AutoEncryptionOptions is omitted.如果创建了内部MongoClient,除了minPoolSize设置为0并且省略了AutoEncryptionOptions之外,它将使用与父级MongoClient相同的选项进行配置。

ca?: string | Buffer | (string | Buffer)[]

Optionally override the trusted CA certificates. (可选)覆盖受信任的CA证书。Default is to trust the well-known CAs curated by Mozilla. 默认情况是信任Mozilla策划的知名CA。Mozilla's CAs are completely replaced when CAs are explicitly specified using this option.当使用此选项显式指定CA时,Mozilla的CA将被完全替换。

cert?: string | Buffer | (string | Buffer)[]

Cert chains in PEM format. PEM格式的证书链。One cert chain should be provided per private key. Each cert chain should consist of the PEM formatted certificate for a provided private key, followed by the PEM formatted intermediate certificates (if any), in order, and not including the root CA (the root CA must be pre-known to the peer, see ca). 每个私钥应提供一个证书链。每个证书链应按顺序由所提供私钥的PEM格式证书组成,然后是PEM格式的中间证书(如果有的话),不包括根CA(根CA必须是对等方已知的,请参阅CA)。When providing multiple cert chains, they do not have to be in the same order as their private keys in key. If the intermediate certificates are not provided, the peer will not be able to validate the certificate, and the handshake will fail.当提供多个证书链时,它们不必与键中的私钥顺序相同。如果不提供中间证书,对等方将无法验证证书,并且握手将失败。

checkServerIdentity?: ((hostname, cert) => Error | undefined)

Type declaration

    • (hostname, cert): Error | undefined
    • Verifies the certificate cert is issued to hostname.

      Returns Error object, populating it with reason, host, and cert on failure. 返回Error对象,在失败时用reasonhostcert填充该对象。On success, returns undefined.成功时,返回undefined

      This function is intended to be used in combination with thecheckServerIdentity option that can be passed to connect and as such operates on a certificate object. 此函数旨在与checkServerIdentity选项结合使用,该选项可传递给连接,因此可对certificate object进行操作。For other purposes, consider using x509.checkHost() instead.出于其他目的,请考虑使用x509.checkHost()

      This function can be overwritten by providing an alternative function as theoptions.checkServerIdentity option that is passed to tls.connect(). 通过提供一个替代函数作为传递给tls.connect()options.checkServerIdentity选项,可以覆盖此函数。The overwriting function can call tls.checkServerIdentity() of course, to augment the checks done with additional verification.覆盖函数当然可以调用tls.checkServerIdentity(),以通过额外的验证来增强所做的检查。

      This function is only called if the certificate passed all other checks, such as being issued by trusted CA (options.ca).只有当证书通过了所有其他检查(例如由受信任的CA(options.ca)颁发)时,才会调用此函数。

      Earlier versions of Node.js incorrectly accepted certificates for a givenhostname if a matching uniformResourceIdentifier subject alternative name was present (see CVE-2021-44531). 如果存在匹配的uniformResourceIdentifier使用者替代名称,早期版本的Node.js错误地接受了给定hostname的证书(请参阅CVE-2021-44531)。Applications that wish to acceptuniformResourceIdentifier subject alternative names can use a customoptions.checkServerIdentity function that implements the desired behavior.希望接受uniformResourceIdentifier主题替代名称的应用程序可以使用实现所需行为的自定义options.checkServerIdentity函数。

      Parameters

      • hostname: string

        The host name or IP address to verify the certificate against.用于验证证书的主机名或IP地址。

      • cert: PeerCertificate

        A certificate object representing the peer's certificate.表示对等方证书的certificate object

      Returns Error | undefined

      Since

      v0.8.4

ciphers?: string

Cipher suite specification, replacing the default. 密码套件规范,替换默认规范。For more information, see modifying the default cipher suite. 有关详细信息,请参阅修改默认密码套件。Permitted ciphers can be obtained via tls.getCiphers(). 允许的密码可以通过tls.getCiphers()获得。Cipher names must be uppercased in order for OpenSSL to accept them.密码名称必须大写,OpenSSL才能接受它们。

compressors: ("none" | "snappy" | "zlib" | "zstd")[]
connectTimeoutMS: number

The time in milliseconds to attempt a connection before timing out.超时前尝试连接的时间(以毫秒为单位)。

credentials?: MongoCredentials
crl?: string | Buffer | (string | Buffer)[]

PEM formatted CRLs (Certificate Revocation Lists).PEM格式的CRL(证书吊销列表)。

dbName: string
directConnection: boolean

Allow a driver to force a Single topology type with a connection string containing one host允许驱动程序强制使用包含一个主机的连接字符串的单一拓扑类型

driverInfo: DriverInfo

Allows a wrapping driver to amend the client metadata generated by the driver to include information about the wrapping driver允许包装驱动程序修改驱动程序生成的客户端元数据,以包含有关包装驱动程序的信息

ecdhCurve?: string

A string describing a named curve or a colon separated list of curve NIDs or names, for example P-521:P-384:P-256, to use for ECDH key agreement. 描述命名曲线或曲线NID或名称的冒号分隔列表的字符串,例如P-521:P-384:P-256,用于ECDH键协商。Set to auto to select the curve automatically. 设置为“自动”可自动选择曲线。Use crypto.getCurves() to obtain a list of available curve names. 使用cryptogetCurves()获取可用曲线名称的列表。On recent releases, openssl ecparam -list_curves will also display the name and description of each available elliptic curve. 在最近的版本中,openssl ecparam-list_curves还将显示每个可用椭圆曲线的名称和描述。Default: tls.DEFAULT_ECDH_CURVE.默认值:tls.DEFAULT_ECDH_CURVE

family?: number
forceServerObjectId: boolean

Force server to assign _id values instead of driver强一致性务器分配_id值而不是驱动程序

heartbeatFrequencyMS: number

heartbeatFrequencyMS controls when the driver checks the state of the MongoDB deployment. hearteatFrequencyMS控制驱动程序何时检查MongoDB部署的状态。Specify the interval (in milliseconds) between checks, counted from the end of the previous check until the beginning of the next one.指定检查之间的间隔(以毫秒为单位),从上一次检查结束到下一次检查开始计数。

hints?: number
hosts: HostAddress[]
key?: string | Buffer | (string | Buffer | KeyObject)[]

Private keys in PEM format. PEM格式的私钥。PEM allows the option of private keys being encrypted. PEM允许选择加密私钥。Encrypted keys will be decrypted with options.passphrase. 加密的键将使用options.passphrase进行解密。Multiple keys using different algorithms can be provided either as an array of unencrypted key strings or buffers, or an array of objects in the form {pem: <string|buffer>[, passphrase: <string>]}. 使用不同算法的多个键可以作为未加密键字符串或缓冲区的数组提供,也可以作为对象的数组提供形式为{pem: <string|buffer>[, passphrase: <string>]}The object form can only occur in an array.对象形式只能出现在数组中。 object.passphrase is optional. object.passphrase是可选的。Encrypted keys will be decrypted with object.passphrase if provided, or options.passphrase if it is not.加密的键将使用object.passphrase(如果提供)进行解密,或者如果没有,则使用options.passphrase进行解密。

loadBalanced: boolean
localAddress?: string
localPort?: number
localThresholdMS: number

The size (in milliseconds) of the latency window for selecting among multiple suitable MongoDB instances.用于在多个合适的MongoDB实例中进行选择的延迟窗口的大小(以毫秒为单位)。

lookup?: LookupFunction
maxConnecting: number

The maximum number of connections that may be in the process of being established concurrently by the connection pool.连接池可能同时建立的最大连接数。

maxIdleTimeMS: number

The maximum number of milliseconds that a connection can remain idle in the pool before being removed and closed.在删除和关闭连接之前,连接在池中可以保持空闲的最大毫秒数。

maxPoolSize: number

The maximum number of connections in the connection pool.连接池中的最大连接数。

metadata: ClientMetadata
minDHSize?: number
minHeartbeatFrequencyMS: number

Sets the minimum heartbeat frequency. In the event that the driver has to frequently re-check a server's availability, it will wait at least this long since the previous check to avoid wasted effort.设置最小检测信号频率。如果驱动程序必须频繁地重新检查服务器的可用性,它将在上次检查后至少等待这么长时间,以避免浪费精力。

minPoolSize: number

The minimum number of connections in the connection pool.连接池中的最小连接数。

monitorCommands: boolean

Enable command monitoring for this client对此客户端启用命令监视

noDelay: boolean

TCP Connection no delayTCP连接无延迟

passphrase?: string

Shared passphrase used for a single private key and/or a PFX.用于单个私钥和/或PFX的共享密码短语。

pfx?: string | Buffer | (string | Buffer | PxfObject)[]

PFX or PKCS12 encoded private key and certificate chain. PFX或PKCS12编码的私钥和证书链。pfx is an alternative to providing key and cert individually. pfx是单独提供键和证书的替代方案。PFX is usually encrypted, if it is, passphrase will be used to decrypt it. PFX通常是加密的,如果是,密码短语将用于解密。Multiple PFX can be provided either as an array of unencrypted PFX buffers, or an array of objects in the form {buf: <string|buffer>[, passphrase: <string>]}. 多个PFX可以作为未加密PFX缓冲区的数组提供,也可以作为对象数组提供,格式为{buf: <string|buffer>[, passphrase: <string>]}The object form can only occur in an array.对象形式只能出现在数组中。object.passphrase is optional. objectpassphrase是可选的。Encrypted PFX will be decrypted with object.passphrase if provided, or options.passphrase if it is not.加密的PFX将使用object.passphrase(如果提供)进行解密,或者如果没有,则使用options.passphrase进行解密。

pkFactory: PkFactory

A primary key factory function for generation of custom _id keys用于生成自定义_id键的主键工厂函数

proxyHost?: string
proxyPassword?: string
proxyPort?: number
proxyUsername?: string
raw: boolean

Enabling the raw option will return a Node.js Buffer which is allocated using allocUnsafe API.启用raw选项将返回使用allocUnsafe API分配的Node.js缓冲区 See this section from the Node.js Docs here for more detail about what "unsafe" refers to in this context.请参阅Node.js文档中的这一部分,了解有关“不安全”在本文中所指内容的更多详细信息。 If you need to maintain your own editable clone of the bytes returned for an extended life time of the process, it is recommended you allocate your own buffer and clone the contents:如果您需要维护自己的可编辑字节克隆,以延长进程的使用寿命,建议您分配自己的缓冲区并克隆内容:

Example

const raw = await collection.findOne({}, { raw: true });
const myBuffer = Buffer.alloc(raw.byteLength);
myBuffer.set(raw, 0);
// Only save and use `myBuffer` beyond this point

Remarks

Please note there is a known limitation where this option cannot be used at the MongoClient level (see NODE-3946).请注意,有一个已知的限制,即此选项不能在MongoClient级别使用(请参阅NODE-3946)。 It does correctly work at Db, Collection, and per operation the same as other BSON options work.它在DbCollection和每个操作中都能正常工作,与其他BSON选项的工作方式相同。

readConcern: ReadConcern
readPreference: ReadPreference
rejectUnauthorized?: boolean

If true the server will reject any connection which is not authorized with the list of supplied CAs. 如果为true,则服务器将拒绝未经所提供CA列表授权的任何连接。This option only has an effect if requestCert is true.只有当requestCert为true时,此选项才有效。

Default

true
replicaSet: string

Specifies the name of the replica set, if the mongod is a member of a replica set.如果mongod是副本集的成员,则指定副本集的名称。

retryReads: boolean

Enables retryable reads.启用可重试读取。

retryWrites: boolean

Enable retryable writes.启用可重试写入。

secureContext?: SecureContext

An optional TLS context object from tls.createSecureContext()tls.creatSecureContext()中的可选TLS上下文对象

secureProtocol?: string

Legacy mechanism to select the TLS protocol version to use, it does not support independent control of the minimum and maximum version, and does not support limiting the protocol to TLSv1.3. 传统机制选择TLS协议版本使用,它不支持独立控制最低和最高版本,也不支持将协议限制为TLSv1.3。Use minVersion and maxVersion instead. The possible values are listed as SSL_METHODS, use the function names as strings. 请改用minVersion和maxVersion。可能的值列为SSL_METHODS,将函数名用作字符串。For example, use 'TLSv1_1_method' to force TLS version 1.1, or 'TLS_method' to allow any TLS protocol version up to TLSv1.3. 例如,使用“TLSv1_method”强制TLS版本1.1,或使用“TLS_method”允许TLSv1.3以下的任何TLS协议版本。It is not recommended to use TLS versions less than 1.2, but it may be required for interoperability. Default: none, see minVersion.不建议使用低于1.2的TLS版本,但可能需要使用该版本才能实现互操作性。默认值:none,请参阅minVersion。

serverApi: ServerApi
serverSelectionTimeoutMS: number

Specifies how long (in milliseconds) to block for server selection before throwing an exception.指定在引发异常之前阻止服务器选择的时间(以毫秒为单位)。

servername?: string
session?: Buffer

An optional Buffer instance containing a TLS session.包含TLS会话的可选缓冲区实例。

socketTimeoutMS: number

The time in milliseconds to attempt a send or receive on a socket before the attempt times out.在尝试超时之前,在套接字上尝试发送或接收的时间(以毫秒为单位)。

srvHost?: string
srvMaxHosts: number

The maximum number of hosts to connect to when using an srv connection string, a setting of 0 means unlimited hosts使用srv连接字符串时要连接到的最大主机数,设置为0表示主机不受限制

srvServiceName: string

Modifies the srv URI to look like:修改srv URI,使其看起来像:

_{srvServiceName}._tcp.{hostname}.{domainname}

Querying this DNS URI is expected to respond with SRV records查询此DNS URI应使用SRV记录进行响应

tls: boolean

NOTE ABOUT TLS Options关于TLS选项的注意事项

If tls is provided as an option, it is equivalent to setting the ssl option.如果将tls作为一个选项提供,则相当于设置ssl选项。

NodeJS native TLS options are passed through to the socket and retain their original types.NodeJS本机TLS选项被传递到套接字并保留其原始类型。

Additional options:其他选项:

nodejs native option原生选项 driver spec equivalent option name驱动程序规范等效选项名称 driver option type驱动程序选项类型
ca tlsCAFile string
crl tlsCRLFile string
cert tlsCertificateKeyFile string
key tlsCertificateKeyFile string
passphrase tlsCertificateKeyFilePassword string
rejectUnauthorized tlsAllowInvalidCertificates boolean
checkServerIdentity tlsAllowInvalidHostnames boolean
see note below tlsInsecure boolean

If tlsInsecure is set to true, then it will set the node native options checkServerIdentity to a no-op and rejectUnauthorized to false.如果tlsInsecure设置为true,则会将Node原生选项checkServerIdentity设置为no-op,并将rejectUnauthorized设置为false

If tlsInsecure is set to false, then it will set the node native options checkServerIdentity to a no-op and rejectUnauthorized to the inverse value of tlsAllowInvalidCertificates. 如果tlsInsecure设置为false,则会将节点本机选项checkServerIdentity设置为no-op,并将rejectUnauthorized设置为tlsAllowInvalidCertificates的反值。If tlsAllowInvalidCertificates is not set, then rejectUnauthorized will be set to true.如果未设置tlsAllowInvalidCertificates,则rejectUnauthorized将设置为true

Note on tlsCAFile, tlsCertificateKeyFile and tlsCRLFile关于tlsCAFiletlsCertificateKeyFiletlsCRLFile的说明

The files specified by the paths passed in to the tlsCAFile, tlsCertificateKeyFile and tlsCRLFile fields are read lazily on the first call to MongoClient.connect. 传入到tlsCAFiletlsCertificateKeyFiletlsCRLFile字段的路径指定的文件在第一次调用MongoClient.connect时延迟读取。Once these files have been read and the ca, cert, crl and key fields are populated, they will not be read again on subsequent calls to MongoClient.connect. 一旦读取了这些文件并填充了cacertcrlkey字段,在随后调用MongoClient.connect时将不会再次读取这些文件。As a result, until the first call to MongoClient.connect, the ca, cert, crl and key fields will be undefined.因此,在第一次调用MongoClient.connect之前,cacertcrlkey字段都是未定义的。

tlsAllowInvalidCertificates: boolean

Bypasses validation of the certificates presented by the mongod/mongos instance绕过mongod/mongos实例提供的证书验证

tlsAllowInvalidHostnames: boolean

Disables hostname validation of the certificate presented by the mongod/mongos instance.禁用mongod/mongos实例提供的证书的主机名验证。

tlsCAFile?: string
tlsCRLFile?: string
tlsCertificateKeyFile?: string
tlsInsecure: boolean

Disables various certificate validations.禁用各种证书验证。

waitQueueTimeoutMS: number

The maximum time in milliseconds that a thread can wait for a connection to become available.线程可以等待连接可用的最长时间(以毫秒为单位)。

writeConcern: WriteConcern
zlibCompressionLevel: 0 | 3 | 9 | 4 | 1 | 2 | 5 | 6 | 7 | 8

An integer that specifies the compression level if using zlib for network compression.如果使用zlib进行网络压缩,则指定压缩级别的整数。

Generated using TypeDoc