Tuesday, 9 May 2017

Variable assignment inside mongoose query not working [duplicate]

for some reason my variable assignment is not working in a mongoose query:

User.findOne({username: msg.username}, function(err, user) {
    languageUser = user.language;
    console.log(user.language);
});

console.log(languageUser);

The console.log(user.language); correctly logs user.language to the console. However, the console.log(languageUser) logs undefined to the console. Should it not log user.language because the value of user.language is assigned to languageUser?

Thanks so much!



via Russell C.

No comments:

Post a Comment