Methods
-
getCursor(changeStream, callback, oldCursor)
-
Safely provides a cursor across resume attempts
Name Type Description changeStreamChangeStream the parent ChangeStream
callbackfunction gets the cursor or error
oldCursorChangeStreamCursor optional when resuming from an error, carry over options from previous cursor
-
processResumeQueue(changeStream, err)
-
Drain the resume queue when a new has become available
Name Type Description changeStreamChangeStream the parent ChangeStream
Name Type Description cursorChangeStreamCursor nullable the new cursor
errError optional error getting a new cursor
Type Definitions
-
AutoEncryptionOptions
-
Properties:
Name Type Argument Description keyVaultClientMongoClient <optional>
A
MongoClientused to fetch keys from a key vaultkeyVaultNamespacestring <optional>
The namespace where keys are stored in the key vault
kmsProvidersobject <optional>
Configuration options that are used by specific KMS providers during key generation, encryption, and decryption.
schemaMapobject <optional>
A map of namespaces to a local JSON schema for encryption
NOTE: Supplying options.schemaMap provides more security than relying on JSON Schemas obtained from the server.
It protects against a malicious server advertising a false JSON Schema, which could trick the client into sending decrypted data that should be encrypted.
Schemas supplied in the schemaMap only apply to configuring automatic encryption for client side encryption.
Other validation rules in the JSON schema will not be enforced by the driver and will result in an error.optionsobject <optional>
An optional hook to catch logging messages from the underlying encryption engine
extraOptionsobject <optional>
bypassAutoEncryptionboolean <optional>
-
AWSEncryptionKeyOptionsobject
-
Configuration options for making an AWS encryption key
Properties:
Name Type Argument Description regionstring The AWS region of the KMS
keystring The Amazon Resource Name (ARN) to the AWS customer master key (CMK)
endpointstring <optional>
An alternate host to send KMS requests to. May include port number
-
AzureEncryptionKeyOptionsobject
-
Configuration options for making an Azure encryption key
Properties:
Name Type Argument Description keyNamestring Key name
keyVaultEndpointstring Key vault URL, typically
<name>.vault.azure.netkeyVersionstring <optional>
Key version
-
ChangeStreamOptions
-
Options that can be passed to a ChangeStream. Note that startAfter, resumeAfter, and startAtOperationTime are all mutually exclusive, and the server will error if more than one is specified.
Properties:
Name Type Argument Default Description fullDocumentstring <optional>
'default' Allowed values: ‘default’, ‘updateLookup’. When set to ‘updateLookup’, the change stream will include both a delta describing the changes to the document, as well as a copy of the entire document that was changed from some time after the change occurred.
maxAwaitTimeMSnumber <optional>
The maximum amount of time for the server to wait on new documents to satisfy a change stream query.
resumeAfterResumeToken <optional>
Allows you to start a changeStream after a specified event. See ChangeStream documentation.
startAfterResumeToken <optional>
Similar to resumeAfter, but will allow you to start after an invalidated event. See ChangeStream documentation.
startAtOperationTimeOperationTime <optional>
Will start the changeStream after the specified operationTime.
batchSizenumber <optional>
1000 The number of documents to return per batch. See aggregation documentation.
collationobject <optional>
Specify collation settings for operation. See aggregation documentation.
readPreferenceReadPreference <optional>
The read preference. Defaults to the read preference of the database or collection. See read preference documentation.
-
DriverInfoOptionsObject
-
Configuration options for drivers wrapping the node driver.
Properties:
Name Type Argument Description namestring <optional>
The name of the driver
versionstring <optional>
The version of the driver
platformstring <optional>
Optional platform information
-
DriverInfoOptionsObject
-
Configuration options for drivers wrapping the node driver.
Properties:
Name Type Argument Description namestring <optional>
The name of the driver
versionstring <optional>
The version of the driver
platformstring <optional>
Optional platform information
-
GCPEncryptionKeyOptionsobject
-
Configuration options for making a GCP encryption key
Properties:
Name Type Argument Description projectIdstring GCP project id
locationstring Location name (e.g. "global")
keyRingstring Key ring name
keyNamestring Key name
keyVersionstring <optional>
Key version
endpointstring <optional>
KMS URL, defaults to
https://www.googleapis.com/auth/cloudkms -
KMSProvidersobject
-
Configuration options that are used by specific KMS providers during key generation, encryption, and decryption.
Properties:
Name Type Argument Description awsobject <optional>
Configuration options for using 'aws' as your KMS provider
Properties
Name Type Argument Description accessKeyIdstring <optional>
The access key used for the AWS KMS provider
secretAccessKeystring <optional>
The secret access key used for the AWS KMS provider
localobject <optional>
Configuration options for using 'local' as your KMS provider
Properties
Name Type Argument Description keyBuffer <optional>
The master key used to encrypt/decrypt data keys. A 96-byte long Buffer.
azureobject <optional>
Configuration options for using 'azure' as your KMS provider
Properties
Name Type Argument Description tenantIdstring <optional>
The tenant ID identifies the organization for the account
clientIdstring <optional>
The client ID to authenticate a registered application
clientSecretstring <optional>
The client secret to authenticate a registered application
identityPlatformEndpointstring <optional>
If present, a host with optional port. E.g. "example.com" or "example.com:443". This is optional, and only needed if customer is using a non-commercial Azure instance (e.g. a government or China account, which use different URLs). Defaults to "login.microsoftonline.com"
gcpobject <optional>
Configuration options for using 'gcp' as your KMS provider
Properties
Name Type Argument Description emailstring <optional>
The service account email to authenticate
privateKeystring | Binary <optional>
A PKCS#8 encrypted key. This can either be a base64 string or a binary representation
endpointstring <optional>
If present, a host with optional port. E.g. "example.com" or "example.com:443". Defaults to "oauth2.googleapis.com"
-
MongoClientOptionsobject
-
- @param {boolean} [bsonRegExp] (default: false) By default, regex returned from MDB will be native to the language. Setting to true will ensure that a BSON.BSONRegExp object is returned.
- 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.
Properties:
Name Type Argument Description poolSizenumber <optional>
(default: 5) The maximum size of the individual server pool
sslboolean <optional>
(default: false) Enable SSL connection. deprecated use
tlsvariantssslValidateboolean <optional>
(default: false) Validate mongod server certificate against Certificate Authority
sslCAbuffer <optional>
(default: undefined) SSL Certificate store binary buffer deprecated use
tlsvariantssslCertbuffer <optional>
(default: undefined) SSL Certificate binary buffer deprecated use
tlsvariantssslKeybuffer <optional>
(default: undefined) SSL Key file binary buffer deprecated use
tlsvariantssslPassstring <optional>
(default: undefined) SSL Certificate pass phrase deprecated use
tlsvariantssslCRLbuffer <optional>
(default: undefined) SSL Certificate revocation list binary buffer deprecated use
tlsvariantscheckServerIdentityboolean | function <optional>
(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
tlsvariantstlsboolean <optional>
(default: false) Enable TLS connections
tlsInsecureboolean <optional>
(default: false) Relax TLS constraints, disabling validation
tlsCAFilestring <optional>
A path to file with either a single or bundle of certificate authorities to be considered trusted when making a TLS connection
tlsCertificateKeyFilestring <optional>
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
tlsCertificateKeyFilePasswordstring <optional>
The password to decrypt the client private key to be used for TLS connections
tlsAllowInvalidCertificatesboolean <optional>
Specifies whether or not the driver should error when the server’s TLS certificate is invalid
tlsAllowInvalidHostnamesboolean <optional>
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
autoReconnectboolean <optional>
(default: true) Enable autoReconnect for single server instances
noDelayboolean <optional>
(default: true) TCP Connection no delay
keepAliveboolean <optional>
(default: true) TCP Connection keep alive enabled
keepAliveInitialDelaynumber <optional>
(default: 120000) The number of milliseconds to wait before initiating keepAlive on the TCP socket
connectTimeoutMSnumber <optional>
(default: 10000) How long to wait for a connection to be established before timing out
socketTimeoutMSnumber <optional>
(default: 0) How long a send or receive on a socket can take before timing out
familynumber <optional>
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
reconnectTriesnumber <optional>
(default: 30) Server attempt to reconnect #times
reconnectIntervalnumber <optional>
(default: 1000) Server will wait # milliseconds between retries
haboolean <optional>
(default: true) Control if high availability monitoring runs for Replicaset or Mongos proxies
haIntervalnumber <optional>
(default: 10000) The High availability period for replicaset inquiry
replicaSetstring <optional>
(default: undefined) The Replicaset set name
secondaryAcceptableLatencyMSnumber <optional>
(default: 15) Cutoff latency point in MS for Replicaset member selection
acceptableLatencyMSnumber <optional>
(default: 15) Cutoff latency point in MS for Mongos proxies selection
connectWithNoPrimaryboolean <optional>
(default: false) Sets if the driver should connect even if no primary is available
authSourcestring <optional>
(default: undefined) Define the database to authenticate against
wnumber | string <optional>
Deprecated The write concern. Use writeConcern instead.
wtimeoutnumber <optional>
Deprecated The write concern timeout. Use writeConcern instead.
jboolean <optional>
(default: false) Deprecated Specify a journal write concern. Use writeConcern instead.
fsyncboolean <optional>
(default: false) Deprecated Specify a file sync write concern. Use writeConcern instead.
writeConcernobject | WriteConcern <optional>
Specify write concern settings.
forceServerObjectIdboolean <optional>
(default: false) Force server to assign _id values instead of driver
serializeFunctionsboolean <optional>
(default: false) Serialize functions on any object
ignoreUndefinedBoolean <optional>
(default: false) Specify if the BSON serializer should ignore undefined fields
rawboolean <optional>
(default: false) Return document results as raw BSON buffers
bufferMaxEntriesnumber <optional>
(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
readPreferenceReadPreference | string <optional>
The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST)
pkFactoryobject <optional>
A primary key factory object for generation of custom _id keys
promiseLibraryobject <optional>
A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible
readConcernobject <optional>
Specify a read concern for the collection (only MongoDB 3.2 or higher supported)
Properties
Name Type Argument Description levelReadConcernLevel <optional>
(default: {Level: 'local'}) Specify a read concern level for the collection operations (only MongoDB 3.2 or higher supported)
maxStalenessSecondsnumber <optional>
(default: undefined) The max staleness to secondary reads (values under 10 seconds cannot be guaranteed)
loggerLevelstring <optional>
(default: undefined) The logging level (error/warn/info/debug)
loggerobject <optional>
(default: undefined) Custom logger object
promoteValuesboolean <optional>
(default: true) Promotes BSON values to native types where possible, set to false to only receive wrapper types
promoteBuffersboolean <optional>
(default: false) Promotes Binary BSON values to native Node Buffers
promoteLongsboolean <optional>
(default: true) Promotes long values to number if they fit inside the 53 bits resolution
domainsEnabledboolean <optional>
(default: false) Enable the wrapping of the callback in the current domain, disabled by default to avoid perf hit
validateOptionsobject <optional>
(default: false) Validate MongoClient passed in options for correctness
appnamestring <optional>
(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.userstring <optional>
(default: undefined) The username for auth
options.auth.passwordstring <optional>
(default: undefined) The password for auth
authMechanismstring <optional>
An authentication mechanism to use for connection authentication, see the authMechanism reference for supported options.
compressionobject <optional>
Type of compression to use: snappy or zlib
readPreferenceTagsarray <optional>
Read preference tags
numberOfRetriesnumber <optional>
(default: 5) The number of retries for a tailable cursor
auto_reconnectboolean <optional>
(default: true) Enable auto reconnecting for single server instances
monitorCommandsboolean <optional>
(default: false) Enable command monitoring for this client
serverApistring | ServerApi <optional>
(default: undefined) The server API version
minSizenumber <optional>
If present, the connection pool will be initialized with minSize connections, and will never dip below minSize connections
useNewUrlParserboolean <optional>
(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.
useUnifiedTopologyboolean <optional>
Enables the new unified topology layer
localThresholdMSnumber <optional>
(default: 15) Only applies to the unified topology The size of the latency window for selecting among multiple suitable servers
serverSelectionTimeoutMSnumber <optional>
(default: 30000) Only applies to the unified topology How long to block for server selection before throwing an error
heartbeatFrequencyMSnumber <optional>
(default: 10000) Only applies to the unified topology The frequency with which topology updates are scheduled
maxPoolSizenumber <optional>
(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.
minPoolSizenumber <optional>
(default: 0) Only applies to the unified topology The minimum number of connections that MUST exist at any moment in a single connection pool.
maxIdleTimeMSnumber <optional>
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.
waitQueueTimeoutMSnumber <optional>
(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.
autoEncryptionAutoEncryptionOptions <optional>
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:
driverInfoDriverInfoOptions <optional>
Allows a wrapping driver to amend the client metadata generated by the driver to include information about the wrapping driver
directConnectionboolean <optional>
(default: false) Enable directConnection
callbackfunction <optional>
The command result callback
-
OperationTime
-
Represents a specific point in time on a server. Can be retrieved by using
Db#command -
ReadConcernObject
-
The MongoDB ReadConcern, which allows for control of the consistency and isolation properties
of the data read from replica sets and replica set shards.- See:
Properties:
Name Type Description level'local' | 'available' | 'majority' | 'linearizable' | 'snapshot' The readConcern Level
-
ReadConcernLevel'local' 'available' 'majority' 'linearizable' 'snapshot'
-
A string specifying the level of a ReadConcern
-
ResumeToken
-
Represents the logical starting point for a new or resuming
ChangeStreamon the server. -
SessionIdObject
-
A BSON document reflecting the lsid of a
ClientSession -
SessionOptionsObject
-
Options to pass when creating a Client Session
Properties:
Name Type Argument Default Description causalConsistencyboolean <optional>
true Whether causal consistency should be enabled on this session
defaultTransactionOptionsTransactionOptions <optional>
The default TransactionOptions to use for transactions started on this session.
-
TransactionOptionsObject
-
Configuration options for a transaction.
Properties:
Name Type Argument Description readConcernReadConcern <optional>
A default read concern for commands in this transaction
writeConcernWriteConcern <optional>
A default writeConcern for commands in this transaction
readPreferenceReadPreference <optional>
A default read preference for commands in this transaction
-
WithTransactionCallback(session){Promise}
-
A user provided function to be run within a transaction
Name Type Description sessionClientSession The parent session of the transaction running the operation. This should be passed into each operation within the lambda.
Returns:
resulting Promise of operations run within this transaction
-
WriteConcernObject
-
A MongoDB WriteConcern, which describes the level of acknowledgement
requested from MongoDB for write operations.- See:
Properties:
Name Type Argument Default Description wnumber | 'majority' | string <optional>
1 requests acknowledgement that the write operation has
propagated to a specified number of mongod hostsjboolean <optional>
false requests acknowledgement from MongoDB that the write operation has
been written to the journalwtimeoutnumber <optional>
a time limit, in milliseconds, for the write concern