I am trying to create a TTL index in MongoDB. I read the answer on here, Answer which was very helpful.
The problem is that the documents just don't expire. Here's the code:
var AcThSchema = new mongoose.Schema({
createdAt: {
type: Date,
expires: '1m',
default: Date.now
},
key: {
type: String,
required: true,
unique: true
}
});
The weird thing that I did notice was that when I use the value 1 instead of Date.now as default for createdAt, the document does get deleted after a few seconds (probably the next time the mongo's TTL process runs)
Why is the document getting deleted for a default value of 1 but not for Date.now?