Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface MongoClientOptions

Describes all possible URI query options for the mongo client描述mongo客户端的所有可能的URI查询选项

see

https://docs.mongodb.com/manual/reference/connection-string

Hierarchy继承层级

Index索引

Properties属性

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

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

appName?: string

The name of the application that created this MongoClient instance. MongoDB 3.4 and newer will print this value in the server log upon establishing each connection. 创建此MongoClient实例的应用程序的名称。MongoDB 3.4及更新版本将在建立每个连接时在服务器日志中打印该值。It is also recorded in the slow query log and profile collections它还记录在慢查询日志和配置文件集合中

auth?: Auth

The auth settings for when connection to server.连接到服务器时的身份验证设置。

authMechanism?: AuthMechanism

Specify the authentication mechanism that MongoDB will use to authenticate the connection.指定MongoDB用于验证连接的身份验证机制。

authMechanismProperties?: AuthMechanismProperties

Specify properties for the specified authMechanism as a comma-separated list of colon-separated key-value pairs.将指定的authMechanism的属性指定为以逗号分隔的冒号分隔的键值对列表。

authSource?: string

Specify the database name associated with the user’s credentials.指定与用户凭据关联的数据库名称。

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). 数据库或视图上的操作不支持自动加密,未绕过的操作将导致错误(请参见libmongocrypt:自动加密允许列表)。To bypass automatic encryption for all operations, set bypassAutoEncryption=true in AutoEncryptionOpts.要绕过所有操作的自动加密,请在AutoEncryptionOpts中设置bypassAutoEncroption=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,则会使用与父MongoClient相同的选项对其进行配置,但minPoolSize设置为0且AutoEncryptionOptions被省略。

bsonRegExp?: boolean

return BSON regular expressions as BSONRegExp instances.返回BSON正则表达式作为BSONRegExp实例。

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

Optionally override the trusted CA certificates. Default is to trust the well-known CAs curated by Mozilla. 可选地覆盖受信任的CA证书。默认设置是信任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. One cert chain should be provided per private key. PEM格式的证书链。每个私钥应提供一个证书链。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.如果没有提供中间证书,对等方将无法验证证书,握手将失败。

checkKeys?: boolean

the serializer will check if keys are valid.

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

Type declaration类型声明

    • (hostname: string, cert: PeerCertificate): Error | undefined
    • Verifies the certificate cert is issued to hostname.验证证书cert是否颁发给hostname

      Returns Error object, populating it with reason, host, and cert on failure. On success, returns undefined.返回Error对象,在失败时用reasonhostcert填充它。成功后,返回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选项结合使用,该选项可以传递给连接,因此可以在证书对象上运行。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主题替代名称的应用程序可以使用实现所需行为的custom.optionscheckServerIdentity函数。

      since

      v0.8.4

      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

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(). Cipher names must be uppercased in order for OpenSSL to accept them.允许的密码可以通过tlsgetCiphers()获得。密码名称必须大写,OpenSSL才能接受它们。

compressors?: string | ("none" | "snappy" | "zlib" | "zstd")[]

An array or comma-delimited string of compressors to enable network compression for communication between this client and a mongod/mongos instance.压缩器的数组或逗号分隔的字符串,用于启用此客户端和mongod/mongos实例之间通信的网络压缩。

connectTimeoutMS?: number

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

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

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

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. 描述用于ECDH密钥协议的命名曲线或以冒号分隔的曲线NID或名称列表的字符串,例如P-521:P-384:P-256。Set to auto to select the curve automatically. 设置为自动以自动选择曲线。Use crypto.getCurves() to obtain a list of available curve names. 使用crypto.getCurves()获取可用曲线名称的列表。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

enableUtf8Validation?: boolean

Enable utf8 validation when deserializing BSON documents. 反序列化BSON文档时启用utf8验证。Defaults to true.默认为true

family?: number
fieldsAsRaw?: Document

allow to specify if there what fields we wish to return as unserialized raw buffer.允许指定是否存在我们希望作为非序列化原始缓冲区返回的字段。

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. heartheatFrequencyMS控制驱动程序何时检查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
ignoreUndefined?: boolean

serialize will not emit undefined fields (default:true)序列化不会发出未定义的字段(默认值:true

journal?: boolean

The journal write concern日记写关注点

deprecated

Please use the writeConcern option instead请改用writeConcern选项

keepAlive?: boolean

TCP Connection keep alive enabledTCP连接保持活动已启用

keepAliveInitialDelay?: number

The number of milliseconds to wait before initiating keepAlive on the TCP socket在TCP套接字上启动keepAlive之前等待的毫秒数

key?: string | Buffer | (string | Buffer | KeyObject)[]

Private keys in PEM format. PEM allows the option of private keys being encrypted. PEM格式的私钥。PEM允许选择加密私钥。Encrypted keys will be decrypted with options.passphrase. 加密的密钥将使用options密码进行解密。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. 对象形式只能出现在数组中。objectpassphrase是可选的。Encrypted keys will be decrypted with object.passphrase if provided, or options.passphrase if it is not.加密密钥将使用object.passphrase(如果提供)或options.passphrase(如果不提供前者)进行解密。

loadBalanced?: boolean

Instruct the driver it is connecting to a load balancer fronting a mongos like service指示驱动程序它正在连接到类似mongos服务的负载平衡器

localAddress?: string
localPort?: number
localThresholdMS?: number

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

logger?: Logger

Custom logger object自定义记录器对象

loggerLevel?: LoggerLevel

The logging level日志记录级别

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.连接池中的最大连接数。

maxStalenessSeconds?: number

Specifies, in seconds, how stale a secondary can be before the client stops using it for read operations.以秒为单位,指定在客户端停止使用辅助文件进行读取操作之前,辅助文件的过时程度。

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. 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可以提供为未加密的PFX缓冲区数组,也可以提供为{buf: <string|buffer>[, passphrase: <string>]}形式的对象数组。The object form can only occur in an array. 对象形式只能出现在数组中。object.passphrase is optional. object.passphrase是可选的。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密钥的主键工厂函数

promiseLibrary?: any

A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible应用程序希望使用的Promise库类(如Bluebird)必须与ES6兼容

deprecated

Setting a custom promise library is deprecated the next major version will use the global Promise constructor only.不推荐设置自定义promise库,下一个主要版本将仅使用全局promise构造函数。

promoteBuffers?: boolean

when deserializing a Binary will return it as a node.js Buffer instance.当反序列化Binary时,它将作为nodejs Buffer实例返回。

promoteLongs?: boolean

when deserializing a Long will fit it into a Number if it's smaller than 53 bits当反序列化Long时,如果Long小于53位,它将适合Number

promoteValues?: boolean

when deserializing will promote BSON values to their Node.js closest equivalent types.当反序列化将把BSON值提升到它们的Node.js最接近的等效类型时。

proxyHost?: string

Configures a Socks5 proxy host used for creating TCP connections.配置用于创建TCP连接的Socks5代理主机。

proxyPassword?: string

Configures a Socks5 proxy password when the proxy in proxyHost requires username/password authentication.当proxyHost中的代理需要用户名/密码身份验证时,配置Socks5代理密码。

proxyPort?: number

Configures a Socks5 proxy port used for creating TCP connections.配置用于创建TCP连接的Socks5代理端口。

proxyUsername?: string

Configures a Socks5 proxy username when the proxy in proxyHost requires username/password authentication.当proxyHost中的代理需要用户名/密码身份验证时,配置Socks5代理用户名。

raw?: boolean

Return document results as raw BSON buffers将文档结果作为原始BSON缓冲区返回

readConcern?: ReadConcernLike

Specify a read concern for the collection (only MongoDB 3.2 or higher supported)指定集合的读取关注点(仅支持MongoDB 3.2或更高版本)

readConcernLevel?: ReadConcernLevel

The level of isolation隔离级别

Specifies the read preferences for this connection指定此连接的读取首选项

readPreferenceTags?: TagSet[]

Specifies the tags document as a comma-separated list of colon-separated key-value pairs.将标记文档指定为以逗号分隔的冒号分隔的键值对列表。

rejectUnauthorized?: boolean

If true the server will reject any connection which is not authorized with the list of supplied CAs. 如果为true,则服务器将拒绝未经授权的任何连接。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.createSecurityContext()中的可选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. 请改用minVersion和maxVersion。The possible values are listed as SSL_METHODS, use the function names as strings. 可能的值列为SSL_METHOD,使用函数名作为字符串。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_1_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. 不建议使用低于1.2的TLS版本,但为了实现互操作性,可能需要使用TLS版本。Default: none, see minVersion.默认值:无,请参阅minVersion。

serializeFunctions?: boolean

serialize the javascript functions (default:false).序列化javascript函数(默认值:false)。

serverApi?: "1" | ServerApi

Server API version服务器API版本

serverSelectionTimeoutMS?: number

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

servername?: string
session?: Buffer
socketTimeoutMS?: number

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

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记录响应

ssl?: boolean

A boolean to enable or disables TLS/SSL for the connection. 用于启用或禁用连接的TLS/SSL的布尔值。(The ssl option is equivalent to the tls option.)(ssl选项等同于tls选项。)

sslCA?: string

SSL Certificate file path.SSL证书文件路径。

sslCRL?: string

SSL Certificate revocation list file path.SSL证书吊销列表文件路径。

sslCert?: string

SSL Certificate file path.SSL证书文件路径。

sslKey?: string

SSL Key file file path.SSL密钥文件路径。

sslPass?: string

SSL Certificate pass phrase.SSL证书密码短语。

sslValidate?: boolean

Validate mongod server certificate against Certificate Authority根据证书颁发机构验证mongod服务器证书

tls?: boolean

Enables or disables TLS/SSL for the connection.启用或禁用连接的TLS/SSL。

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

Specifies the location of a local .pem file that contains the root certificate chain from the Certificate Authority. 指定包含来自证书颁发机构的根证书链的本地pem文件的位置。This file is used to validate the certificate presented by the mongod/mongos instance.该文件用于验证mongod/mongos实例提供的证书。

tlsCertificateFile?: string

Specifies the location of a local TLS Certificate指定本地TLS证书的位置

tlsCertificateKeyFile?: string

Specifies the location of a local .pem file that contains either the client's TLS/SSL certificate and key or only the client's TLS/SSL key when tlsCertificateFile is used to provide the certificate.指定本地pem文件的位置,当tlsCertificateFile用于提供证书时,该文件包含客户端的TLS/SSL证书和密钥,或仅包含客户端的TLS/SSL密钥。

tlsCertificateKeyFilePassword?: string

Specifies the password to de-crypt the tlsCertificateKeyFile.指定解密tlsCertificateKeyFile的密码。

tlsInsecure?: boolean

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

w?: W

The write concern w value写入问题w值

deprecated

Please use the writeConcern option instead请改用writeConcern选项

waitQueueTimeoutMS?: number

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

A MongoDB WriteConcern, which describes the level of acknowledgement requested from MongoDB for write operations.MongoDB WriteConcern,描述从MongoDB请求的写入操作确认级别。

see

https://docs.mongodb.com/manual/reference/write-concern/

wtimeoutMS?: number

The write concern timeout写入问题超时

deprecated

Please use the writeConcern option instead请改用writeConcern选项

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

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

Generated using TypeDoc