mongoose ttl index
export default app => {
const mongoose = app.mongoose;
const Schema = mongoose.Schema;
const VerifyCodeSchema = new Schema(
{
value: { type: String, unique: true }, // code value
type: { type: String, enum: ['email'] }, // verification code type
operation: { type: String, enum: ['login'] }, // type of operation
account: { type: String },
createdAt: { type: Date, default: Date.now, index: { expires: 300 } }, // set ttl, failure is automatically deleted after 5m
},
{
usePushEach: true,
},
);
return mongoose.model('verifyCode', VerifyCodeSchema);
};