I am trying to add follow/unfollow functionality to my app. when I add populate methods in userById it stops showing user info on profile pages. what can I do?
exports.userById = (req, res, next, id)=>{
User.findById(id)
.populate('following', '_id username')
.populate('followers', '_id username')
.exec((err,user)=>{
if(err || !user){
return res.status(400).json({
error: "user not found"
})
}
req.profile=user
next()
})
}