0

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

enter image description here

"UserSchema.index({ createdAt: 1 }, { expireAfterSeconds: 60 })" creates an index that should delete the document with the field "createdAt" 60 seconds after creation

enter image description here

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

Roman
  • 175
  • 2
  • 3
  • 15
  • Hi, this may be similar to your issue, maybe take a look: https://stackoverflow.com/questions/14597241/setting-expiry-time-for-a-collection-in-mongodb-using-mongoose – Mathieu Guyot Apr 03 '23 at 16:56
  • Does this answer your question? [Setting expiry time for a collection in mongodb using mongoose](https://stackoverflow.com/questions/14597241/setting-expiry-time-for-a-collection-in-mongodb-using-mongoose) – Mathieu Guyot Apr 03 '23 at 17:04

0 Answers0