TTL implementation using Java

67 views
Skip to first unread message

Snehal

unread,
Aug 10, 2017, 5:08:33 PM8/10/17
to mongodb-user
I am working on java application using mongo, I want to check if there is any other option to automatically remove documents from collection after particular time period. say after 12 hours .... I checked createIndex option for implementing TTL .. but it needs timestamp column to be present in collection, is there any other way to implement TTL with timestamp column and createIndex option ?

Kevin Adistambha

unread,
Aug 24, 2017, 12:55:19 AM8/24/17
to mongodb-user

Hi,

is there any other way to implement TTL with timestamp column and createIndex option ?

I don’t think so. How else would you know that a document was inserted at a certain point in time in an unambiguous manner? You would have to know that a certain amount of time has passed between a document insertion and a set expiry time (say 12 hours), and using a timestamp field is the most reliable and unambiguous method to do this.

May I ask why you want to implement TTL without a timestamp field and without using the built-in and proven TTL index method? What would be the goal of doing so?

Best regards,
Kevin

Reply all
Reply to author
Forward
0 new messages