Answers for "mongoose ttl index"

1

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);
};
Posted by: Guest on July-30-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language