I've been playing around with the MEAN stack and I was creating some fake data in the dummydata.js file they provide. One thing I noticed is that if I do the following, my console spits out the data I would expect it to:
var allBlogs = function(){
Blog.find().exec(function(err, docs){
console.log(docs);
});
};
console.log(allBlogs());
//returns the data I expect
However, when I try to set the console.log(docs)
as a return value my terminal says undefined
:
var allBlogs = function(){
Blog.find().exec(function(err, docs){
return docs;
});
};
console.log(allBlogs());
// returns 'undefined'
Does anyone know why this is? Can I not return the docs from this function? Is console.logging all that is allowed?