Answer: Mongoose populate() returns empty array with no errors

rnagarajan96

Nagarajan R

Posted on September 15, 2020

Answer: Mongoose populate() returns empty array with no errors

I found that during my little research that it will work:

User
  .findById(req.payload._id)
  .populate({
       path: 'hero.upgrades',
       model: 'Upgrade'
   })
  .exec(function (err, user) {
    if (err){
      console.log(err);
    } else {
      res.status(200).json(user);
      console.log("success");
    }
  });
}

It looks like when user is giving nested object notation i.e. hero.upgrades into populate method, Mongoose…

💖 💪 🙅 🚩
rnagarajan96
Nagarajan R

Posted on September 15, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related