mongodb (mongoose) does not automatically delete documents.
const UserSchema = new mongoose.Schema({
name:String,
}, { timestamps: true })
UserSchema.index({ createdAt: 1 }, { expireAfterSeconds: 60 });
"timestamps: true" creates a date. No time zone specified.
createdAt : 2023-04-03T10:07:26.057+00:00
updatedAt : 2023-04-03T10:07:26.057+00:00
"UserSchema.index({ createdAt: 1 }, { expireAfterSeconds: 60 })" creates an index that should delete the document with the field "createdAt" 60 seconds after creation
The document is not deleted. I've been in pain all day.
I think that either the ttl timer is not working, or the problem is due to the time zone. I don't know