DEV Community

Discussion on: How to solve the "own property" issue in Handlebars with Mongoose

Collapse
 
andyfoster profile image
Andy

Oh my god, thank you so much for this! I couldn't even get the workarounds to work for my setup.

In the end I didn't even have to add the toObject() to my Mongoose Schema. I just added that method to the req.locals in my server.js file.

app.use(function (req, res, next) {
  if (req.user) {
    res.locals.user = req.user.toObject();
  }
  next();
});