middleware/logger/transport-mongodb.js
function initMongo(config, callback) {
  
  var self = this;
  
  // Set db
  self.db = new Db(config.database, new Server(config.host, config.port, {}), {safe: true});
  
  // Get client
  self.db.open(function(err, client) {
    if (err) throw err;
    else {
      self.client = client;
      client.collectionNames(function(err, names) {
        if (err) throw err;
        else {
          var name = config.database + '.' + config.collection;
          var exists = names.filter(function(col) {
            if (col.name == name) return col; 
          });
          
          // Collection options
          var opts = {capped: true, size: config.logSize};
          if (config.logLimit != null) opts.max = config.logLimit;
          
          if (exists.length === 0) {
            client.createCollection(config.collection, opts, function(err, collection) {
              if (err) throw err;
              else {
                self.collection = collection;
                callback.call(self);
              }
            });
          } else {
            // Get collection
            client.collection(config.collection, function(err, collection) {
              if (err) throw err;
              else {
                self.collection = collection;
                // Get collection options » Check if collection has already been capped
                collection.options(function(err, options) {
                  if (err) {
                    throw err;
                  } else {
                    // Check if collection's options match log requirements
                    var ready = (options.capped === true && options.size === opts.size);
                    if ('max' in opts) ready = (ready && options.max === opts.max);
                    if (!ready) {
                      // Convert collection to capped if it's not match log requirements
                      var cmd = {"convertToCapped": config.collection, size: opts.size};
                      if ('max' in opts) cmd.max = opts.max;
                      client.command(cmd, function(err) {
                        if (err) throw err;
                        else {
                          callback.call(self);
                        }
                      });
                    } else {
                      callback.call(self);
                    }
                  }
                });
              }
            });
          }
        }
      });
    }
  });
}
function initMongo(config, callback) {
  
  var self = this;
  
  // Set db
  self.db = new Db(config.database, new Server(config.host, config.port, {}), {safe: true});
  
  // Get client
  self.db.open(function(err, client) {
    if (err) throw err;
    else {
      self.client = client;
      client.collectionNames(function(err, names) {
        if (err) throw err;
        else {
          var name = config.database + '.' + config.collection;
          var exists = names.filter(function(col) {
            if (col.name == name) return col; 
          });
          
          // Collection options
          var opts = {capped: true, size: config.logSize};
          if (config.logLimit != null) opts.max = config.logLimit;
          
          if (exists.length === 0) {
            client.createCollection(config.collection, opts, function(err, collection) {
              if (err) throw err;
              else {
                self.collection = collection;
                callback.call(self);
              }
            });
          } else {
            // Get collection
            client.collection(config.collection, function(err, collection) {
              if (err) throw err;
              else {
                self.collection = collection;
                // Get collection options » Check if collection has already been capped
                collection.options(function(err, options) {
                  if (err) {
                    throw err;
                  } else {
                    // Check if collection's options match log requirements
                    var ready = (options.capped === true && options.size === opts.size);
                    if ('max' in opts) ready = (ready && options.max === opts.max);
                    if (!ready) {
                      // Convert collection to capped if it's not match log requirements
                      var cmd = {"convertToCapped": config.collection, size: opts.size};
                      if ('max' in opts) cmd.max = opts.max;
                      client.command(cmd, function(err) {
                        if (err) throw err;
                        else {
                          callback.call(self);
                        }
                      });
                    } else {
                      callback.call(self);
                    }
                  }
                });
              }
            });
          }
        }
      });
    }
  });
}
function initMongo ( config , callback ) { var self = this ; // Set db self . db = new Db ( config . database , new Server ( config . host , config . port , { } ) , { safe : true } ) ; // Get client self . db . open ( function ( err , client ) { if ( err ) throw err ; else { self . client = client ; client . collectionNames ( function ( err , names ) { if ( err ) throw err ; else { var name = config . database + '.' + config . collection ; var exists = names . filter ( function ( col ) { if ( col . name == name ) return col ; } ) ; // Collection options var opts = { capped : true , size : config . logSize } ; if ( config . logLimit != null ) opts . max = config . logLimit ; if ( exists . length === 0 ) { client . createCollection ( config . collection , opts , function ( err , collection ) { if ( err ) throw err ; else { self . collection = collection ; callback . call ( self ) ; } } ) ; } else { // Get collection client . collection ( config . collection , function ( err , collection ) { if ( err ) throw err ; else { self . collection = collection ; // Get collection options » Check if collection has already been capped collection . options ( function ( err , options ) { if ( err ) { throw err ; } else { // Check if collection's options match log requirements var ready = ( options . capped === true && options . size === opts . size ) ; if ( 'max' in opts ) ready = ( ready && options . max === opts . max ) ; if ( ! ready ) { // Convert collection to capped if it's not match log requirements var cmd = { "convertToCapped" : config . collection , size : opts . size } ; if ( 'max' in opts ) cmd . max = opts . max ; client . command ( cmd , function ( err ) { if ( err ) throw err ; else { callback . call ( self ) ; } } ) ; } else { callback . call ( self ) ; } } } ) ; } } ) ; } } } ) ; } } ) ; }
Initializes the MongoDB Client & Collection

@param {object} config
@param {function} callback
@private
Initializes the MongoDB Client & Collection