score:-1

Accepted answer
exports.getauthorusernames = async (req, res) => {
  if (req.body.data) {
    let mappedarr = req.body.data.map(async nade => {
      await user.findone({ _id: nade.authorid }).then(result => {
        nade.author = result.username;
      });
      return nade;
    });
    res.status(200).send(await promise.all(mappedarr));
  }
};

score:1

exports.getauthorusernames = async (req, res) => {
try{
  if (req.body.data) {
    const mappedarr = req.body.data.map(nade => user.findone({ _id: nade.authorid }));
    const results = await promise.all(mappedarr);
    return res.status(200).send(results);
  }
} catch(e){
//handle exception here
 }
};

Related Query

More Query from same tag