var db = require ('./workingDatabase1').db;
var log = require('log4js').getLogger("EventsRegister");


exports.saveEvent = function (body, error){
  db.events.save(body, function (err, docs){
    if (err){
      log.error("Error ", error);
      error(err);
  }
  });
};

// exports.getEvents = function(query, numrecords, callback){
//   db.events.find(query).limit(numrecords, function(err, docs) {
//     if (err){
//       log.error("Error getting events ", err);
//     }else{
//         callback(docs);
//     }  
//   });
// }  

exports.getEvents = function(query, numrecords, callback){
  db.events.find(query).sort({_id:-1}).limit(numrecords, function(err, docs) {
    if (err){
      log.error("Error getting events ", err);
    }else{
      //console.log("Callback ", docs);
        callback(docs);
    }  
  });
}  
