I'm using Node here and the following function is being used as a controller action. I'm using Mongoose to access a model and within the scope of the Game.findById(), I cannot access any of the variables above it, namely this.player and this.gameId.
Does anyone know what I doing wrong? Note that I want to access the variables where the console.log() statement is, but I can't access it. this.player returns undefined. Thanks in advance for your help.
exports.cleanup = function(req, res) {
this.player = req.body;
this.gameId = req.url.split('/')[2];
debugger;
Game.findById(this.gameId, function(err, game) {
if (err) return err;
console.log(this.player);
});
};