lib/mongo_client.js
function MongoClient(url, options) {
  if (!(this instanceof MongoClient)) return new MongoClient(url, options);
  // Set up event emitter
  EventEmitter.call(this);

  // The internal state
  this.s = {
    url: url,
    options: options || {},
    promiseLibrary: null,
    dbCache: {},
    sessions: []
  };

  // Get the promiseLibrary
  const promiseLibrary = this.s.options.promiseLibrary || Promise;

  // Add the promise to the internal state
  this.s.promiseLibrary = promiseLibrary;
}
function MongoClient(url, options) {
  if (!(this instanceof MongoClient)) return new MongoClient(url, options);
  // Set up event emitter
  EventEmitter.call(this);

  // The internal state
  this.s = {
    url: url,
    options: options || {},
    promiseLibrary: null,
    dbCache: {},
    sessions: []
  };

  // Get the promiseLibrary
  const promiseLibrary = this.s.options.promiseLibrary || Promise;

  // Add the promise to the internal state
  this.s.promiseLibrary = promiseLibrary;
}
function MongoClient ( url , options ) { if ( ! ( this instanceof MongoClient ) ) return new MongoClient ( url , options ) ; // Set up event emitter EventEmitter . call ( this ) ; // The internal state this . s = { url : url , options : options || { } , promiseLibrary : null , dbCache : { } , sessions : [ ] } ; // Get the promiseLibrary const promiseLibrary = this . s . options . promiseLibrary || Promise ; // Add the promise to the internal state this . s . promiseLibrary = promiseLibrary ; }
A string specifying the level of a ReadConcern
@typedef {'local'|'available'|'majority'|'linearizable'|'snapshot'} ReadConcernLevel
@see https://docs.mongodb.com/manual/reference/read-concern/index.html#read-concern-levels
 
Creates a new MongoClient instance
@class
@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.
@param {boolean} [options.sslValidate=false] Validate mongod server certificate against Certificate Authority
@param {buffer} [options.sslCA=undefined] SSL Certificate store binary buffer
@param {buffer} [options.sslCert=undefined] SSL Certificate binary buffer
@param {buffer} [options.sslKey=undefined] SSL Key file binary buffer
@param {string} [options.sslPass=undefined] SSL Certificate pass phrase
@param {buffer} [options.sslCRL=undefined] SSL Certificate revocation list binary buffer
@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=30000] TCP Connection timeout setting
@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.socketTimeoutMS=360000] TCP Socket timeout setting
@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 {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
@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=false] 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.
@param {boolean} [options.useUnifiedTopology] Enables the new unified topology layer
@param {MongoClient~connectCallback} [callback] The command result callback
@return {MongoClient} a MongoClient instance
A string specifying the level of a ReadConcern