Quick code:
var userSchema = new mongoose.Schema({
username: String,
password: {type: String, select: false}
});
userSchema.methods.checkPassword = function(password, done) {
console.log(password); // Password to check
console.log(this.password); // stored password
...
};
I don't want the password to be accessible by default, but I need a method to check against a user inputted password before authenticating the user. I know I can do a query to the DB to include these values, but I'm a bit lost on how I could access the hidden property on the schema method itself. this
in the method itself is just the returned query, so it seems like it is inaccessible? Should I be doing the checkPassword()
function elsewhere?
select:false
properties from within aschema.methods
itself, you have to pass it to a callback. Got it! Thank you. – Railey