In this case, first, you should create an instance method on your schema, so, your code must be something like this :
Before you write this function, you must add two fields in your schema.
1. passwordResetExpire
2. passwordResetToken
and the function is:
userSchema.methods.createPasswordResetToken = function () {
const resetToken = crypto.randomBytes(32).toString('hex');
this.passwordResetToken = crypto.createHash('sha256').update(resetToken).digest('hex');
// Please note that you need to specify a time to expire this token. In this example is (10 min)
this.passwordResetExpire = Date.now() + 10 * 60 * 1000;
return resetToken;
};