Search code examples
node.jsmongodbmongoosemongoose-schemamongoose-populate

Is there an equivalent of Promise.all in mongoose query?


I looked in the docs but couldnt find it. looking for something like the following

let promise = new Promise(someExecutor);
let promise2 = new Promise(executor2);
Promise.all([promise,promise2]).then(someFunc);

let userQ = User.find(someId);
let postQ = Post.find(someIdforPost);
//Mongoose.Query.all([userQ, postQ])?? 

Solution

  • The mongoose find function returns a promise anyways. So you can handle this similar to the 1st example in your code.

    Just use Promise.all([userQ, postQ]).then(someFunc)