Cleanup
This commit is contained in:
328
node_modules/mongodb/lib/mongo_client.js
generated
vendored
328
node_modules/mongodb/lib/mongo_client.js
generated
vendored
@@ -5,6 +5,7 @@ const Db = require('./db');
|
||||
const EventEmitter = require('events').EventEmitter;
|
||||
const inherits = require('util').inherits;
|
||||
const MongoError = require('./core').MongoError;
|
||||
const ValidServerApiVersions = require('./core').ValidServerApiVersions;
|
||||
const deprecate = require('util').deprecate;
|
||||
const WriteConcern = require('./write_concern');
|
||||
const MongoDBNamespace = require('./utils').MongoDBNamespace;
|
||||
@@ -71,103 +72,164 @@ const validOptions = require('./operations/connect').validOptions;
|
||||
* @property {string} [platform] Optional platform information
|
||||
*/
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @typedef AutoEncryptionOptions
|
||||
* @property {MongoClient} [keyVaultClient] A `MongoClient` used to fetch keys from a key vault
|
||||
* @property {string} [keyVaultNamespace] The namespace where keys are stored in the key vault
|
||||
* @property {object} [kmsProviders] Configuration options that are used by specific KMS providers during key generation, encryption, and decryption.
|
||||
* @property {object} [schemaMap] 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.
|
||||
*
|
||||
* @property {object} [options] An optional hook to catch logging messages from the underlying encryption engine
|
||||
* @property {object} [extraOptions]
|
||||
* @property {boolean} [bypassAutoEncryption]
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} MongoClientOptions
|
||||
* @property {number} [poolSize] (**default**: 5) The maximum size of the individual server pool
|
||||
* @property {boolean} [ssl] (**default**: false) Enable SSL connection. *deprecated* use `tls` variants
|
||||
* @property {boolean} [sslValidate] (**default**: false) Validate mongod server certificate against Certificate Authority
|
||||
* @property {buffer} [sslCA] (**default**: undefined) SSL Certificate store binary buffer *deprecated* use `tls` variants
|
||||
* @property {buffer} [sslCert] (**default**: undefined) SSL Certificate binary buffer *deprecated* use `tls` variants
|
||||
* @property {buffer} [sslKey] (**default**: undefined) SSL Key file binary buffer *deprecated* use `tls` variants
|
||||
* @property {string} [sslPass] (**default**: undefined) SSL Certificate pass phrase *deprecated* use `tls` variants
|
||||
* @property {buffer} [sslCRL] (**default**: undefined) SSL Certificate revocation list binary buffer *deprecated* use `tls` variants
|
||||
* @property {boolean|function} [checkServerIdentity] (**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
|
||||
* @property {boolean} [tls] (**default**: false) Enable TLS connections
|
||||
* @property {boolean} [tlsInsecure] (**default**: false) Relax TLS constraints, disabling validation
|
||||
* @property {string} [tlsCAFile] A path to file with either a single or bundle of certificate authorities to be considered trusted when making a TLS connection
|
||||
* @property {string} [tlsCertificateKeyFile] 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
|
||||
* @property {string} [tlsCertificateKeyFilePassword] The password to decrypt the client private key to be used for TLS connections
|
||||
* @property {boolean} [tlsAllowInvalidCertificates] Specifies whether or not the driver should error when the server’s TLS certificate is invalid
|
||||
* @property {boolean} [tlsAllowInvalidHostnames] 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
|
||||
* @property {boolean} [autoReconnect] (**default**: true) Enable autoReconnect for single server instances
|
||||
* @property {boolean} [noDelay] (**default**: true) TCP Connection no delay
|
||||
* @property {boolean} [keepAlive] (**default**: true) TCP Connection keep alive enabled
|
||||
* @property {number} [keepAliveInitialDelay] (**default**: 120000) The number of milliseconds to wait before initiating keepAlive on the TCP socket
|
||||
* @property {number} [connectTimeoutMS] (**default**: 10000) How long to wait for a connection to be established before timing out
|
||||
* @property {number} [socketTimeoutMS] (**default**: 0) How long a send or receive on a socket can take before timing out
|
||||
* @property {number} [family] 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
|
||||
* @property {number} [reconnectTries] (**default**: 30) Server attempt to reconnect #times
|
||||
* @property {number} [reconnectInterval] (**default**: 1000) Server will wait # milliseconds between retries
|
||||
* @property {boolean} [ha] (**default**: true) Control if high availability monitoring runs for Replicaset or Mongos proxies
|
||||
* @property {number} [haInterval] (**default**: 10000) The High availability period for replicaset inquiry
|
||||
* @property {string} [replicaSet] (**default**: undefined) The Replicaset set name
|
||||
* @property {number} [secondaryAcceptableLatencyMS] (**default**: 15) Cutoff latency point in MS for Replicaset member selection
|
||||
* @property {number} [acceptableLatencyMS] (**default**: 15) Cutoff latency point in MS for Mongos proxies selection
|
||||
* @property {boolean} [connectWithNoPrimary] (**default**: false) Sets if the driver should connect even if no primary is available
|
||||
* @property {string} [authSource] (**default**: undefined) Define the database to authenticate against
|
||||
* @property {(number|string)} [w] **Deprecated** The write concern. Use writeConcern instead.
|
||||
* @property {number} [wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
|
||||
* @property {boolean} [j] (**default**: false) **Deprecated** Specify a journal write concern. Use writeConcern instead.
|
||||
* @property {boolean} [fsync] (**default**: false) **Deprecated** Specify a file sync write concern. Use writeConcern instead.
|
||||
* @property {object|WriteConcern} [writeConcern] Specify write concern settings.
|
||||
* @property {boolean} [forceServerObjectId] (**default**: false) Force server to assign _id values instead of driver
|
||||
* @property {boolean} [serializeFunctions] (**default**: false) Serialize functions on any object
|
||||
* @property {Boolean} [ignoreUndefined] (**default**: false) Specify if the BSON serializer should ignore undefined fields
|
||||
* @property {boolean} [raw] (**default**: false) Return document results as raw BSON buffers
|
||||
* @property {number} [bufferMaxEntries] (**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
|
||||
* @property {(ReadPreference|string)} [readPreference] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST)
|
||||
* @property {object} [pkFactory] A primary key factory object for generation of custom _id keys
|
||||
* @property {object} [promiseLibrary] A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible
|
||||
* @property {object} [readConcern] Specify a read concern for the collection (only MongoDB 3.2 or higher supported)
|
||||
* @property {ReadConcernLevel} [readConcern.level] (**default**: {Level: 'local'}) Specify a read concern level for the collection operations (only MongoDB 3.2 or higher supported)
|
||||
* @property {number} [maxStalenessSeconds] (**default**: undefined) The max staleness to secondary reads (values under 10 seconds cannot be guaranteed)
|
||||
* @property {string} [loggerLevel] (**default**: undefined) The logging level (error/warn/info/debug)
|
||||
* @property {object} [logger] (**default**: undefined) Custom logger object
|
||||
* @property {boolean} [promoteValues] (**default**: true) Promotes BSON values to native types where possible, set to false to only receive wrapper types
|
||||
* @property {boolean} [promoteBuffers] (**default**: false) Promotes Binary BSON values to native Node Buffers
|
||||
* @property {boolean} [promoteLongs] (**default**: true) Promotes long values to number if they fit inside the 53 bits resolution
|
||||
* * @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.
|
||||
* @property {boolean} [domainsEnabled] (**default**: false) Enable the wrapping of the callback in the current domain, disabled by default to avoid perf hit
|
||||
* @property {object} [validateOptions] (**default**: false) Validate MongoClient passed in options for correctness
|
||||
* @property {string} [appname] (**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
|
||||
* @property {string} [options.auth.user] (**default**: undefined) The username for auth
|
||||
* @property {string} [options.auth.password] (**default**: undefined) The password for auth
|
||||
* @property {string} [authMechanism] An authentication mechanism to use for connection authentication, see the {@link https://docs.mongodb.com/manual/reference/connection-string/#urioption.authMechanism|authMechanism} reference for supported options.
|
||||
* @property {object} [compression] Type of compression to use: snappy or zlib
|
||||
* @property {array} [readPreferenceTags] Read preference tags
|
||||
* @property {number} [numberOfRetries] (**default**: 5) The number of retries for a tailable cursor
|
||||
* @property {boolean} [auto_reconnect] (**default**: true) Enable auto reconnecting for single server instances
|
||||
* @property {boolean} [monitorCommands] (**default**: false) Enable command monitoring for this client
|
||||
* @property {string|ServerApi} [serverApi] (**default**: undefined) The server API version
|
||||
* @property {number} [minSize] If present, the connection pool will be initialized with minSize connections, and will never dip below minSize connections
|
||||
* @property {boolean} [useNewUrlParser] (**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.
|
||||
* @property {boolean} [useUnifiedTopology] Enables the new unified topology layer
|
||||
* @property {number} [localThresholdMS] (**default**: 15) **Only applies to the unified topology** The size of the latency window for selecting among multiple suitable servers
|
||||
* @property {number} [serverSelectionTimeoutMS] (**default**: 30000) **Only applies to the unified topology** How long to block for server selection before throwing an error
|
||||
* @property {number} [heartbeatFrequencyMS] (**default**: 10000) **Only applies to the unified topology** The frequency with which topology updates are scheduled
|
||||
* @property {number} [maxPoolSize] (**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.
|
||||
* @property {number} [minPoolSize] (**default**: 0) **Only applies to the unified topology** The minimum number of connections that MUST exist at any moment in a single connection pool.
|
||||
* @property {number} [maxIdleTimeMS] **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.
|
||||
* @property {number} [waitQueueTimeoutMS] (**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.
|
||||
* @property {AutoEncryptionOptions} [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](https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/client-side-encryption.rst#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](https://docs.mongodb.com/manual/reference/command/listCollections/#dbcmd.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.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.
|
||||
*
|
||||
* @property {DriverInfoOptions} [driverInfo] Allows a wrapping driver to amend the client metadata generated by the driver to include information about the wrapping driver
|
||||
* @property {boolean} [directConnection] (**default**: false) Enable directConnection
|
||||
* @property {function} [callback] The command result callback
|
||||
*/
|
||||
|
||||
/**
|
||||
* Creates a new MongoClient instance
|
||||
* @class
|
||||
* @constructor
|
||||
* @extends {EventEmitter}
|
||||
* @param {string} url The connection URI string
|
||||
* @param {object} [options] Optional settings
|
||||
* @param {number} [options.poolSize=5] The maximum size of the individual server pool
|
||||
* @param {boolean} [options.ssl=false] Enable SSL connection. *deprecated* use `tls` variants
|
||||
* @param {boolean} [options.sslValidate=false] Validate mongod server certificate against Certificate Authority
|
||||
* @param {buffer} [options.sslCA=undefined] SSL Certificate store binary buffer *deprecated* use `tls` variants
|
||||
* @param {buffer} [options.sslCert=undefined] SSL Certificate binary buffer *deprecated* use `tls` variants
|
||||
* @param {buffer} [options.sslKey=undefined] SSL Key file binary buffer *deprecated* use `tls` variants
|
||||
* @param {string} [options.sslPass=undefined] SSL Certificate pass phrase *deprecated* use `tls` variants
|
||||
* @param {buffer} [options.sslCRL=undefined] SSL Certificate revocation list binary buffer *deprecated* use `tls` variants
|
||||
* @param {boolean|function} [options.checkServerIdentity=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
|
||||
* @param {boolean} [options.tls=false] Enable TLS connections
|
||||
* @param {boolean} [options.tlsInsecure=false] Relax TLS constraints, disabling validation
|
||||
* @param {string} [options.tlsCAFile] A path to file with either a single or bundle of certificate authorities to be considered trusted when making a TLS connection
|
||||
* @param {string} [options.tlsCertificateKeyFile] 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
|
||||
* @param {string} [options.tlsCertificateKeyFilePassword] The password to decrypt the client private key to be used for TLS connections
|
||||
* @param {boolean} [options.tlsAllowInvalidCertificates] Specifies whether or not the driver should error when the server’s TLS certificate is invalid
|
||||
* @param {boolean} [options.tlsAllowInvalidHostnames] 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
|
||||
* @param {boolean} [options.autoReconnect=true] Enable autoReconnect for single server instances
|
||||
* @param {boolean} [options.noDelay=true] TCP Connection no delay
|
||||
* @param {boolean} [options.keepAlive=true] TCP Connection keep alive enabled
|
||||
* @param {number} [options.keepAliveInitialDelay=30000] The number of milliseconds to wait before initiating keepAlive on the TCP socket
|
||||
* @param {number} [options.connectTimeoutMS=10000] How long to wait for a connection to be established before timing out
|
||||
* @param {number} [options.socketTimeoutMS=360000] How long a send or receive on a socket can take before timing out
|
||||
* @param {number} [options.family] 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
|
||||
* @param {number} [options.reconnectTries=30] Server attempt to reconnect #times
|
||||
* @param {number} [options.reconnectInterval=1000] Server will wait # milliseconds between retries
|
||||
* @param {boolean} [options.ha=true] Control if high availability monitoring runs for Replicaset or Mongos proxies
|
||||
* @param {number} [options.haInterval=10000] The High availability period for replicaset inquiry
|
||||
* @param {string} [options.replicaSet=undefined] The Replicaset set name
|
||||
* @param {number} [options.secondaryAcceptableLatencyMS=15] Cutoff latency point in MS for Replicaset member selection
|
||||
* @param {number} [options.acceptableLatencyMS=15] Cutoff latency point in MS for Mongos proxies selection
|
||||
* @param {boolean} [options.connectWithNoPrimary=false] Sets if the driver should connect even if no primary is available
|
||||
* @param {string} [options.authSource=undefined] Define the database to authenticate against
|
||||
* @param {(number|string)} [options.w] The write concern
|
||||
* @param {number} [options.wtimeout] The write concern timeout
|
||||
* @param {boolean} [options.j=false] Specify a journal write concern
|
||||
* @param {boolean} [options.forceServerObjectId=false] Force server to assign _id values instead of driver
|
||||
* @param {boolean} [options.serializeFunctions=false] Serialize functions on any object
|
||||
* @param {Boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields
|
||||
* @param {boolean} [options.raw=false] Return document results as raw BSON buffers
|
||||
* @param {number} [options.bufferMaxEntries=-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
|
||||
* @param {(ReadPreference|string)} [options.readPreference] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST)
|
||||
* @param {object} [options.pkFactory] A primary key factory object for generation of custom _id keys
|
||||
* @param {object} [options.promiseLibrary] A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible
|
||||
* @param {object} [options.readConcern] Specify a read concern for the collection (only MongoDB 3.2 or higher supported)
|
||||
* @param {ReadConcernLevel} [options.readConcern.level='local'] Specify a read concern level for the collection operations (only MongoDB 3.2 or higher supported)
|
||||
* @param {number} [options.maxStalenessSeconds=undefined] The max staleness to secondary reads (values under 10 seconds cannot be guaranteed)
|
||||
* @param {string} [options.loggerLevel=undefined] The logging level (error/warn/info/debug)
|
||||
* @param {object} [options.logger=undefined] Custom logger object
|
||||
* @param {boolean} [options.promoteValues=true] Promotes BSON values to native types where possible, set to false to only receive wrapper types
|
||||
* @param {boolean} [options.promoteBuffers=false] Promotes Binary BSON values to native Node Buffers
|
||||
* @param {boolean} [options.promoteLongs=true] Promotes long values to number if they fit inside the 53 bits resolution
|
||||
* @param {boolean} [options.domainsEnabled=false] Enable the wrapping of the callback in the current domain, disabled by default to avoid perf hit
|
||||
* @param {object} [options.validateOptions=false] Validate MongoClient passed in options for correctness
|
||||
* @param {string} [options.appname=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
|
||||
* @param {string} [options.auth.user=undefined] The username for auth
|
||||
* @param {string} [options.auth.password=undefined] The password for auth
|
||||
* @param {string} [options.authMechanism=undefined] Mechanism for authentication: MDEFAULT, GSSAPI, PLAIN, MONGODB-X509, or SCRAM-SHA-1
|
||||
* @param {object} [options.compression] Type of compression to use: snappy or zlib
|
||||
* @param {boolean} [options.fsync=false] Specify a file sync write concern
|
||||
* @param {array} [options.readPreferenceTags] Read preference tags
|
||||
* @param {number} [options.numberOfRetries=5] The number of retries for a tailable cursor
|
||||
* @param {boolean} [options.auto_reconnect=true] Enable auto reconnecting for single server instances
|
||||
* @param {boolean} [options.monitorCommands=false] Enable command monitoring for this client
|
||||
* @param {number} [options.minSize] If present, the connection pool will be initialized with minSize connections, and will never dip below minSize connections
|
||||
* @param {boolean} [options.useNewUrlParser=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.
|
||||
* @param {boolean} [options.useUnifiedTopology] Enables the new unified topology layer
|
||||
* @param {Number} [options.localThresholdMS=15] **Only applies to the unified topology** The size of the latency window for selecting among multiple suitable servers
|
||||
* @param {Number} [options.serverSelectionTimeoutMS=30000] **Only applies to the unified topology** How long to block for server selection before throwing an error
|
||||
* @param {Number} [options.heartbeatFrequencyMS=10000] **Only applies to the unified topology** The frequency with which topology updates are scheduled
|
||||
* @param {number} [options.maxPoolSize=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.
|
||||
* @param {number} [options.minPoolSize=0] **Only applies to the unified topology** The minimum number of connections that MUST exist at any moment in a single connection pool.
|
||||
* @param {number} [options.maxIdleTimeMS] **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.
|
||||
* @param {number} [options.waitQueueTimeoutMS=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.
|
||||
* @param {AutoEncrypter~AutoEncryptionOptions} [options.autoEncryption] Optionally enable client side auto encryption
|
||||
* @param {DriverInfoOptions} [options.driverInfo] Allows a wrapping driver to amend the client metadata generated by the driver to include information about the wrapping driver
|
||||
* @param {MongoClient~connectCallback} [callback] The command result callback
|
||||
* @return {MongoClient} a MongoClient instance
|
||||
* @param {MongoClientOptions} [options] Optional settings
|
||||
*/
|
||||
function MongoClient(url, options) {
|
||||
options = options || {};
|
||||
if (!(this instanceof MongoClient)) return new MongoClient(url, options);
|
||||
// Set up event emitter
|
||||
EventEmitter.call(this);
|
||||
|
||||
if (options.autoEncryption) require('./encrypter'); // Does CSFLE lib check
|
||||
|
||||
if (options.serverApi) {
|
||||
const serverApiToValidate =
|
||||
typeof options.serverApi === 'string' ? { version: options.serverApi } : options.serverApi;
|
||||
const versionToValidate = serverApiToValidate && serverApiToValidate.version;
|
||||
if (!versionToValidate) {
|
||||
throw new MongoError(
|
||||
`Invalid \`serverApi\` property; must specify a version from the following enum: ["${ValidServerApiVersions.join(
|
||||
'", "'
|
||||
)}"]`
|
||||
);
|
||||
}
|
||||
if (!ValidServerApiVersions.some(v => v === versionToValidate)) {
|
||||
throw new MongoError(
|
||||
`Invalid server API version=${versionToValidate}; must be in the following enum: ["${ValidServerApiVersions.join(
|
||||
'", "'
|
||||
)}"]`
|
||||
);
|
||||
}
|
||||
options.serverApi = serverApiToValidate;
|
||||
}
|
||||
|
||||
// The internal state
|
||||
this.s = {
|
||||
url: url,
|
||||
options: options || {},
|
||||
url,
|
||||
options,
|
||||
promiseLibrary: (options && options.promiseLibrary) || Promise,
|
||||
dbCache: new Map(),
|
||||
sessions: new Set(),
|
||||
writeConcern: WriteConcern.fromOptions(options),
|
||||
readPreference: ReadPreference.fromOptions(options) || ReadPreference.primary,
|
||||
namespace: new MongoDBNamespace('admin')
|
||||
};
|
||||
}
|
||||
@@ -187,7 +249,7 @@ Object.defineProperty(MongoClient.prototype, 'writeConcern', {
|
||||
Object.defineProperty(MongoClient.prototype, 'readPreference', {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return ReadPreference.primary;
|
||||
return this.s.readPreference;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -265,13 +327,13 @@ MongoClient.prototype.close = function(force, callback) {
|
||||
}
|
||||
|
||||
client.topology.close(force, err => {
|
||||
const autoEncrypter = client.topology.s.options.autoEncrypter;
|
||||
if (!autoEncrypter) {
|
||||
completeClose(err);
|
||||
return;
|
||||
const encrypter = client.topology.s.options.encrypter;
|
||||
if (encrypter) {
|
||||
return encrypter.close(client, force, err2 => {
|
||||
completeClose(err || err2);
|
||||
});
|
||||
}
|
||||
|
||||
autoEncrypter.teardown(force, err2 => completeClose(err || err2));
|
||||
completeClose(err);
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -326,17 +388,18 @@ MongoClient.prototype.db = function(dbName, options) {
|
||||
* Check if MongoClient is connected
|
||||
*
|
||||
* @method
|
||||
* @deprecated
|
||||
* @param {object} [options] Optional settings.
|
||||
* @param {boolean} [options.noListener=false] Do not make the db an event listener to the original connection.
|
||||
* @param {boolean} [options.returnNonCachedInstance=false] Control if you want to return a cached instance or have a new one created
|
||||
* @return {boolean}
|
||||
*/
|
||||
MongoClient.prototype.isConnected = function(options) {
|
||||
MongoClient.prototype.isConnected = deprecate(function(options) {
|
||||
options = options || {};
|
||||
|
||||
if (!this.topology) return false;
|
||||
return this.topology.isConnected(options);
|
||||
};
|
||||
}, 'isConnected is deprecated and will be removed in the next major version');
|
||||
|
||||
/**
|
||||
* Connect to MongoDB using a url as documented at
|
||||
@@ -348,84 +411,7 @@ MongoClient.prototype.isConnected = function(options) {
|
||||
* @method
|
||||
* @static
|
||||
* @param {string} url The connection URI string
|
||||
* @param {object} [options] Optional settings
|
||||
* @param {number} [options.poolSize=5] The maximum size of the individual server pool
|
||||
* @param {boolean} [options.ssl=false] Enable SSL connection. *deprecated* use `tls` variants
|
||||
* @param {boolean} [options.sslValidate=false] Validate mongod server certificate against Certificate Authority
|
||||
* @param {buffer} [options.sslCA=undefined] SSL Certificate store binary buffer *deprecated* use `tls` variants
|
||||
* @param {buffer} [options.sslCert=undefined] SSL Certificate binary buffer *deprecated* use `tls` variants
|
||||
* @param {buffer} [options.sslKey=undefined] SSL Key file binary buffer *deprecated* use `tls` variants
|
||||
* @param {string} [options.sslPass=undefined] SSL Certificate pass phrase *deprecated* use `tls` variants
|
||||
* @param {buffer} [options.sslCRL=undefined] SSL Certificate revocation list binary buffer *deprecated* use `tls` variants
|
||||
* @param {boolean|function} [options.checkServerIdentity=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
|
||||
* @param {boolean} [options.tls=false] Enable TLS connections
|
||||
* @param {boolean} [options.tlsInsecure=false] Relax TLS constraints, disabling validation
|
||||
* @param {string} [options.tlsCAFile] A path to file with either a single or bundle of certificate authorities to be considered trusted when making a TLS connection
|
||||
* @param {string} [options.tlsCertificateKeyFile] 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
|
||||
* @param {string} [options.tlsCertificateKeyFilePassword] The password to decrypt the client private key to be used for TLS connections
|
||||
* @param {boolean} [options.tlsAllowInvalidCertificates] Specifies whether or not the driver should error when the server’s TLS certificate is invalid
|
||||
* @param {boolean} [options.tlsAllowInvalidHostnames] 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
|
||||
* @param {boolean} [options.autoReconnect=true] Enable autoReconnect for single server instances
|
||||
* @param {boolean} [options.noDelay=true] TCP Connection no delay
|
||||
* @param {boolean} [options.keepAlive=true] TCP Connection keep alive enabled
|
||||
* @param {number} [options.keepAliveInitialDelay=30000] The number of milliseconds to wait before initiating keepAlive on the TCP socket
|
||||
* @param {number} [options.connectTimeoutMS=10000] How long to wait for a connection to be established before timing out
|
||||
* @param {number} [options.socketTimeoutMS=360000] How long a send or receive on a socket can take before timing out
|
||||
* @param {number} [options.family] 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
|
||||
* @param {number} [options.reconnectTries=30] Server attempt to reconnect #times
|
||||
* @param {number} [options.reconnectInterval=1000] Server will wait # milliseconds between retries
|
||||
* @param {boolean} [options.ha=true] Control if high availability monitoring runs for Replicaset or Mongos proxies
|
||||
* @param {number} [options.haInterval=10000] The High availability period for replicaset inquiry
|
||||
* @param {string} [options.replicaSet=undefined] The Replicaset set name
|
||||
* @param {number} [options.secondaryAcceptableLatencyMS=15] Cutoff latency point in MS for Replicaset member selection
|
||||
* @param {number} [options.acceptableLatencyMS=15] Cutoff latency point in MS for Mongos proxies selection
|
||||
* @param {boolean} [options.connectWithNoPrimary=false] Sets if the driver should connect even if no primary is available
|
||||
* @param {string} [options.authSource=undefined] Define the database to authenticate against
|
||||
* @param {(number|string)} [options.w] The write concern
|
||||
* @param {number} [options.wtimeout] The write concern timeout
|
||||
* @param {boolean} [options.j=false] Specify a journal write concern
|
||||
* @param {boolean} [options.forceServerObjectId=false] Force server to assign _id values instead of driver
|
||||
* @param {boolean} [options.serializeFunctions=false] Serialize functions on any object
|
||||
* @param {Boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields
|
||||
* @param {boolean} [options.raw=false] Return document results as raw BSON buffers
|
||||
* @param {number} [options.bufferMaxEntries=-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
|
||||
* @param {(ReadPreference|string)} [options.readPreference] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST)
|
||||
* @param {object} [options.pkFactory] A primary key factory object for generation of custom _id keys
|
||||
* @param {object} [options.promiseLibrary] A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible
|
||||
* @param {object} [options.readConcern] Specify a read concern for the collection (only MongoDB 3.2 or higher supported)
|
||||
* @param {ReadConcernLevel} [options.readConcern.level='local'] Specify a read concern level for the collection operations (only MongoDB 3.2 or higher supported)
|
||||
* @param {number} [options.maxStalenessSeconds=undefined] The max staleness to secondary reads (values under 10 seconds cannot be guaranteed)
|
||||
* @param {string} [options.loggerLevel=undefined] The logging level (error/warn/info/debug)
|
||||
* @param {object} [options.logger=undefined] Custom logger object
|
||||
* @param {boolean} [options.promoteValues=true] Promotes BSON values to native types where possible, set to false to only receive wrapper types
|
||||
* @param {boolean} [options.promoteBuffers=false] Promotes Binary BSON values to native Node Buffers
|
||||
* @param {boolean} [options.promoteLongs=true] Promotes long values to number if they fit inside the 53 bits resolution
|
||||
* @param {boolean} [options.domainsEnabled=false] Enable the wrapping of the callback in the current domain, disabled by default to avoid perf hit
|
||||
* @param {object} [options.validateOptions=false] Validate MongoClient passed in options for correctness
|
||||
* @param {string} [options.appname=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
|
||||
* @param {string} [options.auth.user=undefined] The username for auth
|
||||
* @param {string} [options.auth.password=undefined] The password for auth
|
||||
* @param {string} [options.authMechanism=undefined] Mechanism for authentication: MDEFAULT, GSSAPI, PLAIN, MONGODB-X509, or SCRAM-SHA-1
|
||||
* @param {object} [options.compression] Type of compression to use: snappy or zlib
|
||||
* @param {boolean} [options.fsync=false] Specify a file sync write concern
|
||||
* @param {array} [options.readPreferenceTags] Read preference tags
|
||||
* @param {number} [options.numberOfRetries=5] The number of retries for a tailable cursor
|
||||
* @param {boolean} [options.auto_reconnect=true] Enable auto reconnecting for single server instances
|
||||
* @param {boolean} [options.monitorCommands=false] Enable command monitoring for this client
|
||||
* @param {number} [options.minSize] If present, the connection pool will be initialized with minSize connections, and will never dip below minSize connections
|
||||
* @param {boolean} [options.useNewUrlParser=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.
|
||||
* @param {boolean} [options.useUnifiedTopology] Enables the new unified topology layer
|
||||
* @param {Number} [options.localThresholdMS=15] **Only applies to the unified topology** The size of the latency window for selecting among multiple suitable servers
|
||||
* @param {Number} [options.serverSelectionTimeoutMS=30000] **Only applies to the unified topology** How long to block for server selection before throwing an error
|
||||
* @param {Number} [options.heartbeatFrequencyMS=10000] **Only applies to the unified topology** The frequency with which topology updates are scheduled
|
||||
* @param {number} [options.maxPoolSize=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.
|
||||
* @param {number} [options.minPoolSize=0] **Only applies to the unified topology** The minimum number of connections that MUST exist at any moment in a single connection pool.
|
||||
* @param {number} [options.maxIdleTimeMS] **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.
|
||||
* @param {number} [options.waitQueueTimeoutMS=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.
|
||||
* @param {AutoEncrypter~AutoEncryptionOptions} [options.autoEncryption] Optionally enable client side auto encryption
|
||||
* @param {DriverInfoOptions} [options.driverInfo] Allows a wrapping driver to amend the client metadata generated by the driver to include information about the wrapping driver
|
||||
* @param {MongoClient~connectCallback} [callback] The command result callback
|
||||
* @param {MongoClientOptions} [options] Optional settings
|
||||
* @return {Promise<MongoClient>} returns Promise if no callback passed
|
||||
*/
|
||||
MongoClient.connect = function(url, options, callback) {
|
||||
@@ -452,10 +438,6 @@ MongoClient.prototype.startSession = function(options) {
|
||||
throw new MongoError('Must connect to a server before calling this method');
|
||||
}
|
||||
|
||||
if (!this.topology.hasSessionSupport()) {
|
||||
throw new MongoError('Current topology does not support sessions');
|
||||
}
|
||||
|
||||
return this.topology.startSession(options, this.s.options);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user