I am trying to run two async queries in MongoDB using Mongoose and ExpressJS.
exports.get_options_data = function (req, res) {
var rooms = [];
var areas = [];
async.parallel({
rooms : AddProperty.distinct("roomQty", function (err, data) {
if (err)
res.send({ code: '500', message: err });
rooms = data;
}),
areas: AddProperty.distinct("area", function (err, data) {
if (err)
res.send({ code: '500', message: err });
areas = data;
})
}, function(err, data){
res.send({ code: '200', rooms: rooms, areas : areas });
})
}
for that, I am using async parallel. I've install async using npm i async
.
What I want is, to execute both these queries and send responses of queries together as combined JSON.
but, I am getting error when I execute this:
TypeError: wrapAsync(...) is not a function
Also, is there any better approach for doing same?