@Indexedを使用してそれを行うことができます アノテーションのexpireAfterSeconds タイプがDateであるフィールドの属性 。大まかに:
@Document
public class SomeEntity {
String id;
@Field
@Indexed(name="someDateFieldIndex", expireAfterSeconds=3600)
Date someDateField;
// rest of code here
}
または、MongoTemplateを操作します :
mongoTemplate
.indexOps(SomeEntity.class)
.ensureIndex(new Index().on("someDateField", Sort.Direction.ASC).expire(3600));