I am trying to query out multiple user profiles and then populate each one of the profiles and send it to the client side of my web application. But it's failing miserably. I have done my research and tried everything but it still won't populate it. Here's my axios request to my backend :
router.get("/all", (req, res) => {
errors = {}
Profile.find().populate('user', ['name', 'avatar'])
.then(profiles => {
if (!profiles) {
errors.noprofile = " there are no profiles"
res.status(404).json(errors)
}
else {
res.json(profiles)
}
}).catch(err => res.json(errors))
})
Here user property of the profile isn't populating and i am getting just a user id in my profile collection. I have used findOne({user:req.user.id}) to fetch a particular user and then populate it using populate('user',['name','avatar']) above in my file and it has worked absolutely fine.