I'm trying to create auto-expiring Mongoose document by setting expires
.
const mySchema = new mongoose.Schema({
title: {
type: String,
required: true
},
content: {
type: String,
required: true
},
expireAt: {
type: Date,
default: Date.now,
index: { expires: 1200 } // Delete after 20 minutes.
}
}, { collection: 'mycollection', timestamps: true });
I want it to terminate after 20 minutes but it keeps on terminating after about 1 - 2 minutes.
I've tried { expires: '20m' }
as well which also deletes document after about 1 - 2 minutes.