I'm building a nodejs app using mongoose. I am trying to change a variable that is outside the mongoose findOne function, but, for some reason, it doesnt change that var.
let existent_teams;
match.findOne({ match_id: match_id }, (err, docs) => {
if(err) console.error(err);
var length = docs.match_teams.length; //Returns 0
existent_teams = length; //Giving existent_teams var the length value
});
console.log(existent_teams); //Returns undefined
And it is returning me that the value of the variable existent_teams is undefined...
I already tried changing the let to const and also to var