I am querying an object from my db using mongoose
, and I want to remove the password
field.
I am executing:
delete user.password;
But the user
object still contain the field.
User.findOne({
'id': id
},'-_id', function(err, user) {
// if there are any errors, return the error before anything else
if (err)
return done(err);
// if no user is found, return the message
if (!user)
return done(null, false);
user.comparePassword(password).then((res) => {
console.log(user);
delete user.password;
console.log(user);
return res ?
done(null, user) : done(null, false);
})
});
Creating a new object and deleting own of its field does work properly in the same environment.
var x = {a:1, b:2};
console.log(x);
delete x.a;
console.log(x)
What am I doing wrong and how can I remove the password field?