exports.getComments = async function(req, res, next) {
try {
console.log('request came for fetching comment');
let foundPlaylist = await Playlist.findById(req.params.playlist_id).populate('comment');
let foundComments = await foundPlaylist.comments.map(async (comment) => {
let com = await Comment.findById(comment._id);
return com;
});
console.log('before sending data', foundComments);
return res.status(200).json(foundComments);
} catch (error) {
return next(error);
}
};
this is the function i use when i call fetching comments for particular playlist . here i use async await but before sending data to front end i got array of empty objects of comments. can you help me with this?