So I am working with Node.js and I need to render an HTML with some data from a collection of my mongoose db, I understand that db.count() is asynchronous so when i do something as follows:
Car.getCount("a", function(err, ocupados){
if(err) throw err;
parqOcupados.push(ocupados);
});
Oh and my getCount function is:
module.exports.getCount = function(lugar, callback){
var query = {lugar: lugar};
Car.count(query, callback);}
I will eventually get undefined pushed into the array since the function is asynchronous as mentioned above. What would be a way to get the value for my getCount pushed into my Array in a correct form?
Thanks in advance for any help provided
via Juan David Ospina
No comments:
Post a Comment