Infinite TTL for MongoDB collection

1.7k views Asked by At

Do we have some way to mark index with expireAfterSeconds property as infinite. I want to do this in order not to be forced to drop index later, and just change TTL using collMod. Or maybe we have some maximum value for expireAfterSeconds property? What do you think?

1

There are 1 answers

2
Philipp On BEST ANSWER

No, you can't. But you can set it to a very high value like 100 years (about 3.000.000.000 seconds).

Alternatively you could abandon the build-in TTL index mechanism and replicate the functionality on the client-side. MongoDBs TTL is quite primitive. All it does is call db.collection.remove({date:{$lt: new Date() - ttl }) at regular intervals. Replicating this on the application-side is often not really much work.