lib/topologies/server.js
function(options) {
  options = options || {};

  // Add event listener
  EventEmitter.call(this);

  // Server instance id
  this.id = id++;

  // Internal state
  this.s = {
    // Options
    options: options,
    // Logger
    logger: Logger('Server', options),
    // Factory overrides
    Cursor: options.cursorFactory || BasicCursor,
    // BSON instance
    bson:
      options.bson ||
      new BSON([
        BSON.Binary,
        BSON.Code,
        BSON.DBRef,
        BSON.Decimal128,
        BSON.Double,
        BSON.Int32,
        BSON.Long,
        BSON.Map,
        BSON.MaxKey,
        BSON.MinKey,
        BSON.ObjectId,
        BSON.BSONRegExp,
        BSON.Symbol,
        BSON.Timestamp
      ]),
    // Pool
    pool: null,
    // Disconnect handler
    disconnectHandler: options.disconnectHandler,
    // Monitor thread (keeps the connection alive)
    monitoring: typeof options.monitoring === 'boolean' ? options.monitoring : true,
    // Is the server in a topology
    inTopology: !!options.parent,
    // Monitoring timeout
    monitoringInterval:
      typeof options.monitoringInterval === 'number' ? options.monitoringInterval : 5000,
    // Topology id
    topologyId: -1,
    compression: { compressors: createCompressionInfo(options) },
    // Optional parent topology
    parent: options.parent
  };

  // If this is a single deployment we need to track the clusterTime here
  if (!this.s.parent) {
    this.s.clusterTime = null;
  }

  // Curent ismaster
  this.ismaster = null;
  // Current ping time
  this.lastIsMasterMS = -1;
  // The monitoringProcessId
  this.monitoringProcessId = null;
  // Initial connection
  this.initialConnect = true;
  // Default type
  this._type = 'server';
  // Set the client info
  this.clientInfo = createClientInfo(options);

  // Max Stalleness values
  // last time we updated the ismaster state
  this.lastUpdateTime = 0;
  // Last write time
  this.lastWriteDate = 0;
  // Stalleness
  this.staleness = 0;
}
function(options) {
  options = options || {};

  // Add event listener
  EventEmitter.call(this);

  // Server instance id
  this.id = id++;

  // Internal state
  this.s = {
    // Options
    options: options,
    // Logger
    logger: Logger('Server', options),
    // Factory overrides
    Cursor: options.cursorFactory || BasicCursor,
    // BSON instance
    bson:
      options.bson ||
      new BSON([
        BSON.Binary,
        BSON.Code,
        BSON.DBRef,
        BSON.Decimal128,
        BSON.Double,
        BSON.Int32,
        BSON.Long,
        BSON.Map,
        BSON.MaxKey,
        BSON.MinKey,
        BSON.ObjectId,
        BSON.BSONRegExp,
        BSON.Symbol,
        BSON.Timestamp
      ]),
    // Pool
    pool: null,
    // Disconnect handler
    disconnectHandler: options.disconnectHandler,
    // Monitor thread (keeps the connection alive)
    monitoring: typeof options.monitoring === 'boolean' ? options.monitoring : true,
    // Is the server in a topology
    inTopology: !!options.parent,
    // Monitoring timeout
    monitoringInterval:
      typeof options.monitoringInterval === 'number' ? options.monitoringInterval : 5000,
    // Topology id
    topologyId: -1,
    compression: { compressors: createCompressionInfo(options) },
    // Optional parent topology
    parent: options.parent
  };

  // If this is a single deployment we need to track the clusterTime here
  if (!this.s.parent) {
    this.s.clusterTime = null;
  }

  // Curent ismaster
  this.ismaster = null;
  // Current ping time
  this.lastIsMasterMS = -1;
  // The monitoringProcessId
  this.monitoringProcessId = null;
  // Initial connection
  this.initialConnect = true;
  // Default type
  this._type = 'server';
  // Set the client info
  this.clientInfo = createClientInfo(options);

  // Max Stalleness values
  // last time we updated the ismaster state
  this.lastUpdateTime = 0;
  // Last write time
  this.lastWriteDate = 0;
  // Stalleness
  this.staleness = 0;
}
function ( options ) { options = options || { } ; // Add event listener EventEmitter . call ( this ) ; // Server instance id this . id = id ++ ; // Internal state this . s = { // Options options : options , // Logger logger : Logger ( 'Server' , options ) , // Factory overrides Cursor : options . cursorFactory || BasicCursor , // BSON instance bson : options . bson || new BSON ( [ BSON . Binary , BSON . Code , BSON . DBRef , BSON . Decimal128 , BSON . Double , BSON . Int32 , BSON . Long , BSON . Map , BSON . MaxKey , BSON . MinKey , BSON . ObjectId , BSON . BSONRegExp , BSON . Symbol , BSON . Timestamp ] ) , // Pool pool : null , // Disconnect handler disconnectHandler : options . disconnectHandler , // Monitor thread (keeps the connection alive) monitoring : typeof options . monitoring === 'boolean' ? options . monitoring : true , // Is the server in a topology inTopology : ! ! options . parent , // Monitoring timeout monitoringInterval : typeof options . monitoringInterval === 'number' ? options . monitoringInterval : 5000 , // Topology id topologyId : - 1 , compression : { compressors : createCompressionInfo ( options ) } , // Optional parent topology parent : options . parent } ; // If this is a single deployment we need to track the clusterTime here if ( ! this . s . parent ) { this . s . clusterTime = null ; } // Curent ismaster this . ismaster = null ; // Current ping time this . lastIsMasterMS = - 1 ; // The monitoringProcessId this . monitoringProcessId = null ; // Initial connection this . initialConnect = true ; // Default type this . _type = 'server' ; // Set the client info this . clientInfo = createClientInfo ( options ) ; // Max Stalleness values // last time we updated the ismaster state this . lastUpdateTime = 0 ; // Last write time this . lastWriteDate = 0 ; // Stalleness this . staleness = 0 ; }
Creates a new Server instance
@class
@param {boolean} [options.reconnect=true] Server will attempt to reconnect on loss of connection
@param {number} [options.reconnectTries=30] Server attempt to reconnect #times
@param {number} [options.reconnectInterval=1000] Server will wait # milliseconds between retries
@param {number} [options.monitoring=true] Enable the server state monitoring (calling ismaster at monitoringInterval)
@param {number} [options.monitoringInterval=5000] The interval of calling ismaster when monitoring is enabled.
@param {Cursor} [options.cursorFactory=Cursor] The cursor factory class used for all query cursors
@param {string} options.host The server host
@param {number} options.port The server port
@param {number} [options.size=5] Server connection pool size
@param {boolean} [options.keepAlive=true] TCP Connection keep alive enabled
@param {number} [options.keepAliveInitialDelay=300000] Initial delay before TCP keep alive enabled
@param {boolean} [options.noDelay=true] TCP Connection no delay
@param {number} [options.connectionTimeout=30000] TCP Connection timeout setting
@param {number} [options.socketTimeout=360000] TCP Socket timeout setting
@param {boolean} [options.ssl=false] Use SSL for connection
@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 {Buffer} [options.ca] SSL Certificate store binary buffer
@param {Buffer} [options.crl] SSL Certificate revocation store binary buffer
@param {Buffer} [options.cert] SSL Certificate binary buffer
@param {Buffer} [options.key] SSL Key file binary buffer
@param {string} [options.passphrase] SSL Certificate pass phrase
@param {boolean} [options.rejectUnauthorized=true] Reject unauthorized server certificates
@param {string} [options.servername=null] String containing the server name requested via TLS SNI.
@param {boolean} [options.promoteLongs=true] Convert Long values from the db into Numbers if they fit into 53 bits
@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 {string} [options.appname=null] Application name, passed in on ismaster call and logged in mongod server logs. Maximum size 128 bytes.
@param {boolean} [options.domainsEnabled=false] Enable the wrapping of the callback in the current domain, disabled by default to avoid perf hit.
@param {boolean} [options.monitorCommands=false] Enable command monitoring for this topology
@return {Server} A cursor instance
@fires Server#connect
@fires Server#close
@fires Server#error
@fires Server#timeout
@fires Server#parseError
@fires Server#reconnect
@fires Server#reconnectFailed
@fires Server#serverHeartbeatStarted
@fires Server#serverHeartbeatSucceeded
@fires Server#serverHeartbeatFailed
@fires Server#topologyOpening
@fires Server#topologyClosed
@fires Server#topologyDescriptionChanged
@property {string} type the topology type.
@property {string} parserType the parser type used (c++ or js).
Creates a new Server instance