Execute multiple queries at once in Mongoose Execute multiple queries at once in Mongoose mongoose mongoose

Execute multiple queries at once in Mongoose


If you are expecting only one result by both of your conditions then you could use User.findOne - it will return the first found result.

User.findOne({ $or:  [    { _id: req.body.userId },    { username: decodedUser.username}  ]}, (err, user) => {  console.log("user\n", user)})

Edit

Since you said that you need to get 2 results and you want to have then in the result you can also run 2 queries in parallel and use promises to get the result. E.g.

Promise.all([  User.find({ _id: req.body.userId }),  User.find({ username: decodedUser.username})]).then( ([ user, member ]) => {  console.log( util.format( "user=%O member=%O", user, member ) );});