'Loopback 3 Mongodb dynamic ttl

So I am trying to make a TTL index in Loopback 3 and I saw that you need to add the "expireAfterSeconds" options and pass a number to it directly.

"indexes":{
    "expireAt_1":{
        "keys": {"createdOn": 1},
        "options":{"expireAfterSeconds": 2592000}
     }
}

I was wondering if it is somehow possible to replace the value dynamically. Basically a booking is kept for 1 day but if the user enabled reporting bookings will be kept for 1 year (maybe even multiple years depending on their licence in the future)

So my question, how can I pass different TTL values depending on whether the company has reporting enabled or not?

If it is not possible, what would be the best way to achieve this nonetheless, knowing it might be kept for maybe for even longer periods (max 5 years probably)?

Thanks in advance!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source