lib/mongodb/mongodb-core/lib/connection/pool.js
function authenticateLiveConnections(self, args, cb) {
    // Get the current viable connections
    var connections = self.allConnections();
    // Allow nothing else to use the connections while we authenticate them
    self.availableConnections = [];
    self.inUseConnections = [];
    self.connectingConnections = [];

    var connectionsCount = connections.length;
    var error = null;
    // No connections available, return
    if (connectionsCount === 0) {
      self.authenticating = false;
      return callback(null);
    }

    // Authenticate the connections
    for (var i = 0; i < connections.length; i++) {
      authenticate(self, args, connections[i], function(err, result) {
        connectionsCount = connectionsCount - 1;

        // Store the error
        if (err) error = err;

        // Processed all connections
        if (connectionsCount === 0) {
          // Auth finished
          self.authenticating = false;
          // Add the connections back to available connections
          self.availableConnections = self.availableConnections.concat(connections);
          // We had an error, return it
          if (error) {
            // Log the error
            if (self.logger.isError()) {
              self.logger.error(
                f(
                  '[%s] failed to authenticate against server %s:%s',
                  self.id,
                  self.options.host,
                  self.options.port
                )
              );
            }

            return cb(error, result);
          }
          cb(null, result);
        }
      });
    }
  }
function authenticateLiveConnections(self, args, cb) {
    // Get the current viable connections
    var connections = self.allConnections();
    // Allow nothing else to use the connections while we authenticate them
    self.availableConnections = [];
    self.inUseConnections = [];
    self.connectingConnections = [];

    var connectionsCount = connections.length;
    var error = null;
    // No connections available, return
    if (connectionsCount === 0) {
      self.authenticating = false;
      return callback(null);
    }

    // Authenticate the connections
    for (var i = 0; i < connections.length; i++) {
      authenticate(self, args, connections[i], function(err, result) {
        connectionsCount = connectionsCount - 1;

        // Store the error
        if (err) error = err;

        // Processed all connections
        if (connectionsCount === 0) {
          // Auth finished
          self.authenticating = false;
          // Add the connections back to available connections
          self.availableConnections = self.availableConnections.concat(connections);
          // We had an error, return it
          if (error) {
            // Log the error
            if (self.logger.isError()) {
              self.logger.error(
                f(
                  '[%s] failed to authenticate against server %s:%s',
                  self.id,
                  self.options.host,
                  self.options.port
                )
              );
            }

            return cb(error, result);
          }
          cb(null, result);
        }
      });
    }
  }
function authenticateLiveConnections ( self , args , cb ) { // Get the current viable connections var connections = self . allConnections ( ) ; // Allow nothing else to use the connections while we authenticate them self . availableConnections = [ ] ; self . inUseConnections = [ ] ; self . connectingConnections = [ ] ; var connectionsCount = connections . length ; var error = null ; // No connections available, return if ( connectionsCount === 0 ) { self . authenticating = false ; return callback ( null ) ; } // Authenticate the connections for ( var i = 0 ; i < connections . length ; i ++ ) { authenticate ( self , args , connections [ i ] , function ( err , result ) { connectionsCount = connectionsCount - 1 ; // Store the error if ( err ) error = err ; // Processed all connections if ( connectionsCount === 0 ) { // Auth finished self . authenticating = false ; // Add the connections back to available connections self . availableConnections = self . availableConnections . concat ( connections ) ; // We had an error, return it if ( error ) { // Log the error if ( self . logger . isError ( ) ) { self . logger . error ( f ( '[%s] failed to authenticate against server %s:%s' , self . id , self . options . host , self . options . port ) ) ; } return cb ( error , result ) ; } cb ( null , result ) ; } } ) ; } }
Authenticate all live connections
Authenticate all live connections