Puedes hacerlo usando @Indexed
expireAfterSeconds
de la anotación atributo sobre un campo cuyo tipo es Date
.Aproximadamente:
@Document
public class SomeEntity {
String id;
@Field
@Indexed(name="someDateFieldIndex", expireAfterSeconds=3600)
Date someDateField;
// rest of code here
}
O manipulando un MongoTemplate
:
mongoTemplate
.indexOps(SomeEntity.class)
.ensureIndex(new Index().on("someDateField", Sort.Direction.ASC).expire(3600));