mongoose ttl index

Solutions on MaxInterview for mongoose ttl index by the best coders in the world

showing results for - "mongoose ttl index"
Mirko
08 Sep 2017
1export default app => {
2  const mongoose = app.mongoose;
3  const Schema = mongoose.Schema;
4
5  const VerifyCodeSchema = new Schema(
6    {
7      value: { type: String, unique: true }, // code value
8      type: { type: String, enum: ['email'] }, // verification code type
9      operation: { type: String, enum: ['login'] }, // type of operation
10      account: { type: String },
11      createdAt: { type: Date, default: Date.now, index: { expires: 300 } }, // set ttl, failure is automatically deleted after 5m
12    },
13    {
14      usePushEach: true,
15    },
16  );
17
18  return mongoose.model('verifyCode', VerifyCodeSchema);
19};