lib/topologies/mongos.js
function(seedlist, options) {
  options = options || {};

  // Get replSet Id
  this.id = id++;

  // Internal state
  this.s = {
    options: Object.assign({}, options),
    // 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
      ]),
    // Factory overrides
    Cursor: options.cursorFactory || BasicCursor,
    // Logger instance
    logger: Logger('Mongos', options),
    // Seedlist
    seedlist: seedlist,
    // Ha interval
    haInterval: options.haInterval ? options.haInterval : 10000,
    // Disconnect handler
    disconnectHandler: options.disconnectHandler,
    // Server selection index
    index: 0,
    // Connect function options passed in
    connectOptions: {},
    // Are we running in debug mode
    debug: typeof options.debug === 'boolean' ? options.debug : false,
    // localThresholdMS
    localThresholdMS: options.localThresholdMS || 15,
    // Client info
    clientInfo: createClientInfo(options)
  };

  // Set the client info
  this.s.options.clientInfo = createClientInfo(options);

  // Log info warning if the socketTimeout < haInterval as it will cause
  // a lot of recycled connections to happen.
  if (
    this.s.logger.isWarn() &&
    this.s.options.socketTimeout !== 0 &&
    this.s.options.socketTimeout < this.s.haInterval
  ) {
    this.s.logger.warn(
      f(
        'warning socketTimeout %s is less than haInterval %s. This might cause unnecessary server reconnections due to socket timeouts',
        this.s.options.socketTimeout,
        this.s.haInterval
      )
    );
  }

  // Disconnected state
  this.state = DISCONNECTED;

  // Current proxies we are connecting to
  this.connectingProxies = [];
  // Currently connected proxies
  this.connectedProxies = [];
  // Disconnected proxies
  this.disconnectedProxies = [];
  // Index of proxy to run operations against
  this.index = 0;
  // High availability timeout id
  this.haTimeoutId = null;
  // Last ismaster
  this.ismaster = null;

  // Description of the Replicaset
  this.topologyDescription = {
    topologyType: 'Unknown',
    servers: []
  };

  // Highest clusterTime seen in responses from the current deployment
  this.clusterTime = null;

  // Add event listener
  EventEmitter.call(this);
}
function(seedlist, options) {
  options = options || {};

  // Get replSet Id
  this.id = id++;

  // Internal state
  this.s = {
    options: Object.assign({}, options),
    // 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
      ]),
    // Factory overrides
    Cursor: options.cursorFactory || BasicCursor,
    // Logger instance
    logger: Logger('Mongos', options),
    // Seedlist
    seedlist: seedlist,
    // Ha interval
    haInterval: options.haInterval ? options.haInterval : 10000,
    // Disconnect handler
    disconnectHandler: options.disconnectHandler,
    // Server selection index
    index: 0,
    // Connect function options passed in
    connectOptions: {},
    // Are we running in debug mode
    debug: typeof options.debug === 'boolean' ? options.debug : false,
    // localThresholdMS
    localThresholdMS: options.localThresholdMS || 15,
    // Client info
    clientInfo: createClientInfo(options)
  };

  // Set the client info
  this.s.options.clientInfo = createClientInfo(options);

  // Log info warning if the socketTimeout < haInterval as it will cause
  // a lot of recycled connections to happen.
  if (
    this.s.logger.isWarn() &&
    this.s.options.socketTimeout !== 0 &&
    this.s.options.socketTimeout < this.s.haInterval
  ) {
    this.s.logger.warn(
      f(
        'warning socketTimeout %s is less than haInterval %s. This might cause unnecessary server reconnections due to socket timeouts',
        this.s.options.socketTimeout,
        this.s.haInterval
      )
    );
  }

  // Disconnected state
  this.state = DISCONNECTED;

  // Current proxies we are connecting to
  this.connectingProxies = [];
  // Currently connected proxies
  this.connectedProxies = [];
  // Disconnected proxies
  this.disconnectedProxies = [];
  // Index of proxy to run operations against
  this.index = 0;
  // High availability timeout id
  this.haTimeoutId = null;
  // Last ismaster
  this.ismaster = null;

  // Description of the Replicaset
  this.topologyDescription = {
    topologyType: 'Unknown',
    servers: []
  };

  // Highest clusterTime seen in responses from the current deployment
  this.clusterTime = null;

  // Add event listener
  EventEmitter.call(this);
}
function ( seedlist , options ) { options = options || { } ; // Get replSet Id this . id = id ++ ; // Internal state this . s = { options : Object . assign ( { } , options ) , // 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 ] ) , // Factory overrides Cursor : options . cursorFactory || BasicCursor , // Logger instance logger : Logger ( 'Mongos' , options ) , // Seedlist seedlist : seedlist , // Ha interval haInterval : options . haInterval ? options . haInterval : 10000 , // Disconnect handler disconnectHandler : options . disconnectHandler , // Server selection index index : 0 , // Connect function options passed in connectOptions : { } , // Are we running in debug mode debug : typeof options . debug === 'boolean' ? options . debug : false , // localThresholdMS localThresholdMS : options . localThresholdMS || 15 , // Client info clientInfo : createClientInfo ( options ) } ; // Set the client info this . s . options . clientInfo = createClientInfo ( options ) ; // Log info warning if the socketTimeout < haInterval as it will cause // a lot of recycled connections to happen. if ( this . s . logger . isWarn ( ) && this . s . options . socketTimeout !== 0 && this . s . options . socketTimeout < this . s . haInterval ) { this . s . logger . warn ( f ( 'warning socketTimeout %s is less than haInterval %s. This might cause unnecessary server reconnections due to socket timeouts' , this . s . options . socketTimeout , this . s . haInterval ) ) ; } // Disconnected state this . state = DISCONNECTED ; // Current proxies we are connecting to this . connectingProxies = [ ] ; // Currently connected proxies this . connectedProxies = [ ] ; // Disconnected proxies this . disconnectedProxies = [ ] ; // Index of proxy to run operations against this . index = 0 ; // High availability timeout id this . haTimeoutId = null ; // Last ismaster this . ismaster = null ; // Description of the Replicaset this . topologyDescription = { topologyType : 'Unknown' , servers : [ ] } ; // Highest clusterTime seen in responses from the current deployment this . clusterTime = null ; // Add event listener EventEmitter . call ( this ) ; }
Creates a new Mongos instance
@class
@param {array} seedlist A list of seeds for the replicaset
@param {number} [options.haInterval=5000] The High availability period for replicaset inquiry
@param {Cursor} [options.cursorFactory=Cursor] The cursor factory class used for all query cursors
@param {number} [options.size=5] Server connection pool size
@param {boolean} [options.keepAlive=true] TCP Connection keep alive enabled
@param {number} [options.keepAliveInitialDelay=0] Initial delay before TCP keep alive enabled
@param {number} [options.localThresholdMS=15] Cutoff latency point in MS for MongoS proxy selection
@param {boolean} [options.noDelay=true] TCP Connection no delay
@param {number} [options.connectionTimeout=1000] TCP Connection timeout setting
@param {number} [options.socketTimeout=0] 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 {string} [options.servername=null] String containing the server name requested via TLS SNI.
@param {boolean} [options.rejectUnauthorized=true] Reject unauthorized server certificates
@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 {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 {Mongos} A cursor instance
@fires Mongos#connect
@fires Mongos#reconnect
@fires Mongos#joined
@fires Mongos#left
@fires Mongos#failed
@fires Mongos#fullsetup
@fires Mongos#all
@fires Mongos#serverHeartbeatStarted
@fires Mongos#serverHeartbeatSucceeded
@fires Mongos#serverHeartbeatFailed
@fires Mongos#topologyOpening
@fires Mongos#topologyClosed
@fires Mongos#topologyDescriptionChanged
@property {string} type the topology type.
@property {string} parserType the parser type used (c++ or js).
Creates a new Mongos instance