[JAVA-2579] TTL implementation using Java Created: 10/Aug/17  Updated: 11/Sep/19  Resolved: 14/Aug/17

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Snehal [X] Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

I am working on java application using mongo, I want to check if there is any other option to remove documents from collection after some time period... 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 ?



 Comments   
Comment by Ross Lawley [ 14/Aug/17 ]

Hi Snehal.

Thanks for the ticket, just to let you kno the best place for questions regarding MongoDB usage or the Java driver specifics is the mongodb-user mailinglist or stackoverflow as you will reach a boarder audience there. If your business requires an answer from MongoDB within a time frame then we do offer production support.

From the documentation, you can see that the TTL index requires a date time value to work:

TTL indexes expire documents after the specified number of seconds has passed since the indexed field value; i.e. the expiration threshold is the indexed field value plus the specified number of seconds.

If the field is an array, and there are multiple date values in the index, MongoDB uses lowest (i.e. earliest) date value in the array to calculate the expiration threshold.

If the indexed field in a document is not a date or an array that holds a date value(s), the document will not expire.

If a document does not contain the indexed field, the document will not expire.

If you have further questions regarding TTL please follow up on one of the forums and post a link here and I'll endeavour to follow up there.

All the best,

Ross

Generated at Thu Feb 08 08:57:35 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.