q.all() to resolve multiple mongoose queries concurrently
AFAIK, q.all()
only handles arrays of promises, not objects of promises (like you're passing). Also, since Mongoose's .exec()
returns a promise already, you don't have to wrap them using q(...)
(although it doesn't hurt if you do).
Try this:
var promises = [ aircraftModel.findOne({_id: tailNumber}).exec(), faaAircraftModel.findOne({_id: tailNumber.substring(1)}).exec()];q.all(promises).then(...);
An alternative to using q
on newer releases of Node is to use the native Promise.all
method with mongoose's mpromise:
var promises = [ aircraftModel.findOne({_id: tailNumber}).exec(), faaAircraftModel.findOne({_id: tailNumber.substring(1)}).exec()];Promise.all(promises).then(function(results) { console.log(results);}).catch(function(err){ console.log(err);});