I have a node.js app that uses mongoose to connect to a mongodb; i need to select all the documents inserted and i i've problems with async stuff.
I've made a model with the following function:
exports.listItems=function() {
Ticket.find({}, function(err,tkts) {
console.log(tkts);
return tkts;
});
}
I correctly see the value of "tkts", but when i call it from:
exports.list = function(req,res) {
var items=db.listItems();
console.log("Items:"+items);
res.render('list', { title: title, items:items });
}
defined in app.js as:
app.get('/list', routes.list);
items is undefined (i think because of non-async definition of db.list()).
What am i doing wrong and how can it be corrected?