so I need to automatically delete document from collection after 2 minutes if paramter isValidatedis set to false, now I made this:
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const Model = mongoose.model;
const UserSchema = new Schema(
{
email: {
type: String,
},
username: { type: String },
createdAt: {
type: Date,
default: Date.now,
},
points: {
type: Number,
default: 0,
},
validation: {
type: String,
},
isValidated: {
type: Boolean,
default: false,
},
roles: [
{
type: mongoose.Schema.Types.ObjectId,
ref: "Role",
},
],
password: {
type: String,
},
},
{ collection: "users" }
);
UserSchema.index(
{ createdAt: 1 },
{
expireAfterSeconds: 120,
partialFilterExpression: { isValidated: false },
}
);
const User = Model("User", UserSchema);
module.exports = User;
But this .index is not working, and I don't know why.