Mongodb自动删除过期的数据——TTL索引
2018年11月08日 15:21:31 lead_myLead 阅读数:62
使用spring-data-mongodb 2.0.9中的
Document document = new Document();
document.append("createTime",1);
IndexOptions indexOptions = new IndexOptions();
indexOptions.expireAfter(300L,TimeUnit.SECONDS);
this.mongoTemplate.getCollection("test").createIndex(document,indexOptions);
createTime是时间字段
使用spring-data-mongodb 1.7.0中的
BasicDBObject bson = new BasicDBObject();
bson.append("createTime",1);
BasicDBObject options = new BasicDBObject();
options.append("expireAfterSeconds",7200);
this.mongoTemplate.getCollection("test").createIndex(bson,options);
2162

被折叠的 条评论
为什么被折叠?



