Můžete to udělat pomocí @Indexed expireAfterSeconds anotace atribut nad polem, jehož typ je Date .Zhruba:
@Document
public class SomeEntity {
String id;
@Field
@Indexed(name="someDateFieldIndex", expireAfterSeconds=3600)
Date someDateField;
// rest of code here
}
Nebo manipulací s MongoTemplate :
mongoTemplate
.indexOps(SomeEntity.class)
.ensureIndex(new Index().on("someDateField", Sort.Direction.ASC).expire(3600));