How to define mongoose method in schema class with using nestjs/mongoose? How to define mongoose method in schema class with using nestjs/mongoose? mongoose mongoose

How to define mongoose method in schema class with using nestjs/mongoose?


You can use below approach to achieve this.

@Schema()export class Auth extends Document {    ...        validatePassword: Function;}export const AuthSchema = SchemaFactory.createForClass(Auth);AuthSchema.methods.validatePassword = async function (password: string): Promise<boolean> {    return bcrypt.compareAsync(password, this.password);};