I need to mention that I'm new to Node.js in general but I'm not sure why for the following code will give me different outputs in console for questions
and allQuestions
variable ?
var models = require('./models')(mongoose);
var query = models.Question.find({});
var questions = Array();
query.exec(function(err, allQuestions){
//catch the error;
questions = allQuestions;
console.log(allQuestions);
});
console.log(questions);
Output of questions variable will be only: Mongoose: questions.find({}) { fields: undefined }
while allQuestions
will contain all the questions from database.
I need to know why ?
Also I need that my question
variable contains allQuestions
from database.