MongoDB Driver API for Node.js (original) (raw)
poolSize
number
(default: 5) The maximum size of the individual server pool
ssl
boolean
(default: false) Enable SSL connection. deprecated use tls
variants
sslValidate
boolean
(default: false) Validate mongod server certificate against Certificate Authority
sslCA
buffer
(default: undefined) SSL Certificate store binary buffer deprecated use tls
variants
sslCert
buffer
(default: undefined) SSL Certificate binary buffer deprecated use tls
variants
sslKey
buffer
(default: undefined) SSL Key file binary buffer deprecated use tls
variants
sslPass
string
(default: undefined) SSL Certificate pass phrase deprecated use tls
variants
sslCRL
buffer
(default: undefined) SSL Certificate revocation list binary buffer deprecated use tls
variants
checkServerIdentity
boolean|function
(default: true) Ensure we check server identify during SSL, set to false to disable checking. Only works for Node 0.12.x or higher. You can pass in a boolean or your own checkServerIdentity override function. deprecated use tls
variants
tls
boolean
(default: false) Enable TLS connections
tlsInsecure
boolean
(default: false) Relax TLS constraints, disabling validation
tlsCAFile
string
A path to file with either a single or bundle of certificate authorities to be considered trusted when making a TLS connection
tlsCertificateKeyFile
string
A path to the client certificate file or the client private key file; in the case that they both are needed, the files should be concatenated
tlsCertificateKeyFilePassword
string
The password to decrypt the client private key to be used for TLS connections
tlsAllowInvalidCertificates
boolean
Specifies whether or not the driver should error when the server’s TLS certificate is invalid
tlsAllowInvalidHostnames
boolean
Specifies whether or not the driver should error when there is a mismatch between the server’s hostname and the hostname specified by the TLS certificate
autoReconnect
boolean
(default: true) Enable autoReconnect for single server instances
noDelay
boolean
(default: true) TCP Connection no delay
keepAlive
boolean
(default: true) TCP Connection keep alive enabled
keepAliveInitialDelay
number
(default: 120000) The number of milliseconds to wait before initiating keepAlive on the TCP socket
connectTimeoutMS
number
(default: 10000) How long to wait for a connection to be established before timing out
socketTimeoutMS
number
(default: 0) How long a send or receive on a socket can take before timing out
family
number
Version of IP stack. Can be 4, 6 or null (default). If null, will attempt to connect with IPv6, and will fall back to IPv4 on failure
reconnectTries
number
(default: 30) Server attempt to reconnect #times
reconnectInterval
number
(default: 1000) Server will wait # milliseconds between retries
ha
boolean
(default: true) Control if high availability monitoring runs for Replicaset or Mongos proxies
haInterval
number
(default: 10000) The High availability period for replicaset inquiry
replicaSet
string
(default: undefined) The Replicaset set name
secondaryAcceptableLatencyMS
number
(default: 15) Cutoff latency point in MS for Replicaset member selection
acceptableLatencyMS
number
(default: 15) Cutoff latency point in MS for Mongos proxies selection
connectWithNoPrimary
boolean
(default: false) Sets if the driver should connect even if no primary is available
authSource
string
(default: undefined) Define the database to authenticate against
w
number|string
Deprecated The write concern. Use writeConcern instead.
wtimeout
number
Deprecated The write concern timeout. Use writeConcern instead.
j
boolean
(default: false) Deprecated Specify a journal write concern. Use writeConcern instead.
fsync
boolean
(default: false) Deprecated Specify a file sync write concern. Use writeConcern instead.
writeConcern
object|WriteConcern
Specify write concern settings.
forceServerObjectId
boolean
(default: false) Force server to assign _id values instead of driver
serializeFunctions
boolean
(default: false) Serialize functions on any object
ignoreUndefined
Boolean
(default: false) Specify if the BSON serializer should ignore undefined fields
raw
boolean
(default: false) Return document results as raw BSON buffers
bufferMaxEntries
number
(default: -1) Sets a cap on how many operations the driver will buffer up before giving up on getting a working connection, default is -1 which is unlimited
readPreference
ReadPreference|string
The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST)
pkFactory
object
A primary key factory object for generation of custom _id keys
promiseLibrary
object
A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible
readConcern
object
Specify a read concern for the collection (only MongoDB 3.2 or higher supported)
Properties
Name | Type | Argument | Description |
---|---|---|---|
level | ReadConcernLevel | (default: {Level: 'local'}) Specify a read concern level for the collection operations (only MongoDB 3.2 or higher supported) |
maxStalenessSeconds
number
(default: undefined) The max staleness to secondary reads (values under 10 seconds cannot be guaranteed)
loggerLevel
string
(default: undefined) The logging level (error/warn/info/debug)
logger
object
(default: undefined) Custom logger object
promoteValues
boolean
(default: true) Promotes BSON values to native types where possible, set to false to only receive wrapper types
promoteBuffers
boolean
(default: false) Promotes Binary BSON values to native Node Buffers
promoteLongs
boolean
(default: true) Promotes long values to number if they fit inside the 53 bits resolution
domainsEnabled
boolean
(default: false) Enable the wrapping of the callback in the current domain, disabled by default to avoid perf hit
validateOptions
object
(default: false) Validate MongoClient passed in options for correctness
appname
string
(default: undefined) 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. It is also recorded in the slow query log and profile collections
options.auth.user
string
(default: undefined) The username for auth
options.auth.password
string
(default: undefined) The password for auth
authMechanism
string
An authentication mechanism to use for connection authentication, see the authMechanism reference for supported options.
compression
object
Type of compression to use: snappy or zlib
readPreferenceTags
array
Read preference tags
numberOfRetries
number
(default: 5) The number of retries for a tailable cursor
auto_reconnect
boolean
(default: true) Enable auto reconnecting for single server instances
monitorCommands
boolean
(default: false) Enable command monitoring for this client
minSize
number
If present, the connection pool will be initialized with minSize connections, and will never dip below minSize connections
useNewUrlParser
boolean
(default: true) Determines whether or not to use the new url parser. Enables the new, spec-compliant, url parser shipped in the core driver. This url parser fixes a number of problems with the original parser, and aims to outright replace that parser in the near future. Defaults to true, and must be explicitly set to false to use the legacy url parser.
useUnifiedTopology
boolean
Enables the new unified topology layer
localThresholdMS
number
(default: 15) Only applies to the unified topology The size of the latency window for selecting among multiple suitable servers
serverSelectionTimeoutMS
number
(default: 30000) Only applies to the unified topology How long to block for server selection before throwing an error
heartbeatFrequencyMS
number
(default: 10000) Only applies to the unified topology The frequency with which topology updates are scheduled
maxPoolSize
number
(default: 10) Only applies to the unified topology The maximum number of connections that may be associated with a pool at a given time. This includes in use and available connections.
minPoolSize
number
(default: 0) Only applies to the unified topology The minimum number of connections that MUST exist at any moment in a single connection pool.
maxIdleTimeMS
number
Only applies to the unified topology The maximum amount of time a connection should remain idle in the connection pool before being marked idle. The default is infinity.
waitQueueTimeoutMS
number
(default: 0) Only applies to the unified topology The maximum amount of time operation execution should wait for a connection to become available. The default is 0 which means there is no limit.
autoEncryption
Optionally enable client side auto encryption.
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.Automatic encryption requires the authenticated user to have the listCollections privilege action.
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.keyVaultClient is not passed.
- AutoEncryptionOptions.bypassAutomaticEncryption is 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.
driverInfo
Allows a wrapping driver to amend the client metadata generated by the driver to include information about the wrapping driver
directConnection
boolean
(default: false) Enable directConnection
callback
function
The command result callback