Remove user password from json response not working for me

// Customize the JSON representation to exclude the password field
userSchema.methods.toJSON = function () {
const user = this.toObject();
delete user.password;
return user;
};

The above codes not working for me.
Someone should me help me.