I am trying to do a Redis-like collection in MongoDB. I need a collection of documents that expire and are automatically deleted after a certain time.

I can use TTL Indexes but with this, every document on my collection is deleted after a fixed amount of time (The time set on the index). I need that every document expires after a parameterized TTL, for example, in the same collection, I would like to insert a document that expires after 30 seconds and right after that, another that expires in like, 120 seconds.

Does MongoDB support this use case? or for this I should use Redis and store a TTL Key? (exactly what I need, but I would have to add Redis to the program while I already have Mongo)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.