lib/util/mongo.js
function dropDb(config, dbUser, dbName, cb){
  log.logger.trace({user: dbUser, name: dbName}, 'drop database');
  
  var url = config.mongoUrl;
  var admin = config.mongo.admin_auth.user;
  var admin_pass = config.mongo.admin_auth.pass;

  MongoClient.connect(url, function(err, dbObj){
    if (err) return handleError(null, err, 'cannot open mongodb connection', cb);

    var dbToDrop = dbObj.db(dbName);
    dbToDrop.authenticate(admin, admin_pass, {'authSource': 'admin'}, function(err){
      if(err) return handleError(dbObj, err, 'can not authenticate admin user', cb);

      dbToDrop.removeUser(dbUser, function(err){
        if(err){
          log.logger.error(err, 'failed to remove user');
        }
        dbToDrop.dropDatabase(function(err){
          if(err) return handleError(dbObj, err, 'failed to drop database', cb);
          dbObj.close();
          return cb();
        });
      });
    });
  });
}
function dropDb(config, dbUser, dbName, cb){
  log.logger.trace({user: dbUser, name: dbName}, 'drop database');
  
  var url = config.mongoUrl;
  var admin = config.mongo.admin_auth.user;
  var admin_pass = config.mongo.admin_auth.pass;

  MongoClient.connect(url, function(err, dbObj){
    if (err) return handleError(null, err, 'cannot open mongodb connection', cb);

    var dbToDrop = dbObj.db(dbName);
    dbToDrop.authenticate(admin, admin_pass, {'authSource': 'admin'}, function(err){
      if(err) return handleError(dbObj, err, 'can not authenticate admin user', cb);

      dbToDrop.removeUser(dbUser, function(err){
        if(err){
          log.logger.error(err, 'failed to remove user');
        }
        dbToDrop.dropDatabase(function(err){
          if(err) return handleError(dbObj, err, 'failed to drop database', cb);
          dbObj.close();
          return cb();
        });
      });
    });
  });
}
function dropDb ( config , dbUser , dbName , cb ) { log . logger . trace ( { user : dbUser , name : dbName } , 'drop database' ) ; var url = config . mongoUrl ; var admin = config . mongo . admin_auth . user ; var admin_pass = config . mongo . admin_auth . pass ; MongoClient . connect ( url , function ( err , dbObj ) { if ( err ) return handleError ( null , err , 'cannot open mongodb connection' , cb ) ; var dbToDrop = dbObj . db ( dbName ) ; dbToDrop . authenticate ( admin , admin_pass , { 'authSource' : 'admin' } , function ( err ) { if ( err ) return handleError ( dbObj , err , 'can not authenticate admin user' , cb ) ; dbToDrop . removeUser ( dbUser , function ( err ) { if ( err ) { log . logger . error ( err , 'failed to remove user' ) ; } dbToDrop . dropDatabase ( function ( err ) { if ( err ) return handleError ( dbObj , err , 'failed to drop database' , cb ) ; dbObj . close ( ) ; return cb ( ) ; } ) ; } ) ; } ) ; } ) ; }
drop a database
drop a database