MongoDB TTL expiry after 18 Months

Does MongoDB consider leap year for TTL index? example I want to retain documents for 18 months, if I put conversion of 18 months to seconds, how will I consider leap years?

Hi @Paul_N_A1 welcome to the community

Does MongoDB consider leap year for TTL index?

I don’t believe so. However there are two possibilities on using a TTL index: setting expireAfterSeconds, or a certain expiry date. See the Expire Data from Collections by Setting TTL page for details.

Thus, if you need a document to expire after 18 months by accounting for leap years, you can use the second method there to predetermine the date when the document should be removed.

Best regards
Kevin

1 Like