So I have this object I get from mongoose, it's a user. I want to delete the hashed password field but I can't seem te remove it.
Tried the following:
apiRoutes.get('/user/:id', function(req, res, next) {
User.findById(req.params.id, function(err, post) {
if (err) return next(err);
delete post['password'];
res.json(post);
});
});
There's definitely a password field there, when I debug/console.log the object it prints out the password.
EDIT: Solved it by passing an option to the mongoose call:
User.findById(req.params.id, '-password', function(err, post) { /* ... */ });
But still doesn't explain why delete doesn't work?