Please bear with me on this. I can't seem to get my head round how I will be able to update the variable outside the FindOne function.
So:
var userPostCount;
userPostsModel.findOne({'profileID':req.session.id}, function(err, usersPostCountDB) {
if(usersPostCountDB){
userPostCount = req.body.postsCount + 1;
} else {
console.log('There was an error getting the postsCount');
}
});
I thought it should be able to find the userPostCount variable as it's the next level up in the scope chain.
Any ideas how I will be able to access it please? I need that variable to be outside of the function as I will be using it later for other mongoose activities.
I am getting the userPostCount as undefined.
Thanks in advance for the help!
PS: I looked around for other questions on SO but the solution on other answers don't seem to work for me.
Shayan