Skip to content

Instantly share code, notes, and snippets.

@kim3er
Forked from Sigmus/gist:4014642
Last active June 12, 2017 21:49
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kim3er/6594588 to your computer and use it in GitHub Desktop.
Save kim3er/6594588 to your computer and use it in GitHub Desktop.
Example of parallel Mongoose execution.
var performers;
performers = {};
async.parallel({
conductor: function(callback) {
return conductor.find({}, function(err, result) {
return callback(err, result);
});
},
soloist: function(callback) {
return soloist.find({}, function(err, result) {
return callback(err, result);
});
},
orchestra: function(callback) {
return orchestra.find({}, function(err, result) {
return callback(err, result);
});
},
chamber: function(callback) {
return chamber.find({}, function(err, result) {
return callback(err, result);
});
}
}, function(err, performers) {
return res.json(performers);
});
@thomporter
Copy link

If you're not going to do any processing on the result from mongoose, then there's no need to setup your own callback, just pass the async callback in to the find method, eg:

...
conductor: function(callback) {
  return conductor.find({}, callback)
}
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment