I’ve been tasked with creating a TTL index on a logging table: delete after three days. However, the field they want me to use was created as a string, not a timestamp:
There are no good date fields to use in its place. The collection currently has 160M records, most of which will be deleted. I can see a few options, but none of them sound particularly appealing:
- Create a new timestamp field and use a trigger to update it based on the string field.
- Use $dateFromString in the TTL index definition.
- Extract the timestamp from the _id field and use that (probably fine).
Just looking for opinions on what will be the most performant, or if there’s an option 4 I’m not seeing. Thank you!