Does creating a TTL index delete out pre-existing records that are beyond the TTL threshold?

I’m currently creating a TTL index for a collection and I’m wondering if this creation will delete out existing records, or if that’s a separate operation. For instance, there are records with a “creationDate” that’s 50 days ago and I’m creating a TTL index on creationDate that will expire records after 30 days. Will anything beyond the 30 days be deleted out upon TTL index creation?

Hi Mason,

Yes, it will mark the documents with creationDate more than 50 days ago eligible for deletion and will delete those when the TTL worker runs. For more information you can read the behaviour of TTL indexes from here - https://www.mongodb.com/docs/manual/core/index-ttl/#behavior

Hi Akshat,

I created the TTL index yesterday but records beyond the 30 days are still there. This is true for every collection I added the index to. It’s deleting out ones that hit the 30 day mark that existed prior, but nothing beyond that. It seems the process doesn’t work as noted above.