As documentation says, one of the restrictions is: TTL indexes are a single-field indexes. mongodb - TTL Index definition with Spring Data - Stack Overflow When you create an TTL index for a field in the collection, there will be a single thread in the background . Spring Data MongoDB how to set index ttl from system property. The indexes are order by the value of the field specified in the index. @Indexed. Better purge data first, then create index on smaller collection, or create TTL index when creating the collection. org.springframework.data.mongodb.core.index.IndexOperations java code ... Changed in MongoDB 4.2 Starting in version 4.2, for featureCompatibilityVersion set to "4.2" or greater, MongoDB removes the Index Name Length limit of 127 byte maximum. No, it is not possible. Mongodb can actually set the expiration time of data just like Redis1. MongoDB 2.2 or higher supports TTL (Time-To-Live) indexes. TTL (Time-To-Live) indexes are special single-field indexes that MongoDB can use to automatically remove documents from a collection after a certain amount of time. The repository follows the Spring Data-centric approach and comes with more flexible and complex API operations, based on the well-known access patterns in all Spring . TTL index is a special index in MongoDB, which can automatically delete documents after a certain time. Expired data may exist beyond the 60 second period between runs of the TTL monitor. MongoDB Repositories :: Spring Docs A background thread in MongoDB reads the values in the index and removes expired documents from the collection (usually every minute). answered Oct 16, 2018 at 10:20. When you index a date array with a TTL index, MongoDB chooses the earliest (lowest) date in the array for computing the expiry date. In that below case for nested object spring data mongodb creating multiple TTL index for Class (ClassA). Update TTL Indexed Field expiry date later - MongoDB Application of TTL indexes can be in Shopping Carts, Login sessions, Event logs etc where the data needs to be retained only for a certain period of time. collection.createIndex(Indexes.ascending("date"), new IndexOptions().expireAfter(1L, TimeUnit.MINUTES)); Ttl1.java You can use a TTL index for queries like a regular index. So far, you cannot directly annotate an inherited field, and can partially annotation getter or setters. 6. To expire data after a specified number of seconds has passed since the indexed field, create a TTL index on a field that holds values of BSON date type or an array of BSON date-typed objects and specify a positive non-zero value in the expireAfterSeconds field. Method ensures that there is a TTL index on expireAt field. When you create the index, you specify the amount of time after the document should expire. Mongodb can actually set the expiration time of data just like Redis1. In that below case for nested object spring data mongodb creating multiple TTL index for Class(ClassA). TTL index is a special index in MongoDB, which can automatically delete documents after a certain time. org.springframework.data.mongodb.core.index.Index.on java code examples ... 44. What'S New In Spring Data Mongodb 2.1; What'S New In Spring Data Mongodb 2.0; What'S New In Spring Data Mongodb 1.10; What'S New In Spring Data Mongodb 1.9; What'S New In Spring Data Mongodb 1.8; What'S New In Spring Data Mongodb 1.7; Dependencies.