Delete expired token from db #393
-
I have a collection with some tokens and I want to delete then after they are expired. Example:
After each login I want to delete all the old tokens, based on a time in second (example, lifetime=3600). I will need to compare the date on my item (field created_at) with my lifetime parameter. Would something like this work? How to compare datas for delete on Beanie?
Thanks!! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey! I think TTL indexes will work in your case. You can add it using |
Beta Was this translation helpful? Give feedback.
Hey! I think TTL indexes will work in your case. You can add it using
IndexModel
: https://beanie-odm.dev/tutorial/indexes/#multi-field-indexes . Here is the MongoDB doc about TTL indexes: https://www.mongodb.com/docs/manual/core/index-ttl/