I wrote this function to get a document from the end of the collection in MongoDB. When I try calling this function in index.js, it returns undefined.
index.js:
app.get('/', authenticate, function(req, res){
  // console.log("DATA: " + getWorldStatsData());
    everything = {
      worldstats: getWorldStatsData(),
    }
    res.render('index', {
      data: everything
  })
})
and my function:
function getWorldStatsData(){
    db.collection('worldstats').find({}).sort({"statistic_taken_at":-1}).limit(1).toArray((err, stats)=>{
      return stats
    })
  // return stats
}
 
    