I'm trying to create self destructive schema in NestJs(typeScript) project using mangoose
and @nestjs/mongoose
library, but couldn't able to rectify a way to implement it . I know how to do it in express framework using js but didn't found any documentation for TS with NestJs
Also updated my code like below ,but still isn't working
import { Prop, Schema, SchemaFactory, SchemaOptions } from '@nestjs/mongoose';
import * as mangoose from 'mongoose';
export type OtpDocument = Otp & mangoose.Document;
// @Schema({ timestamps: { createdAt: { type: Date, expires: 20 } } })
@Schema()
export class Otp {
@Prop({ type: mangoose.Schema.Types.ObjectId, ref: 'User' })
user: any;
@Prop({ expires: 3600 })
OTP: number;
@Prop()
createdAt: Date;
@Prop({ default: Date.now() + 20000 })
expireAt: Date;
}
export const OtpSchema = SchemaFactory.createForClass(Otp);
OtpSchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 });