Mongoose supports nested populating (see in the docs: https://mongoosejs.com/docs/populate.html#deep-populate). Note that you have to specify your model name of post schema where I´ve put the “post-model-name” placeholder.
So you could try something like this:
User.findById(req.user._id)
.populate({
path: 'viewed_posts',
populate: {
path: 'post',
model: 'post-model-name'
}
})
.exec();
CLICK HERE to find out more related problems solutions.