用expireAfterSeconds索引的Spring Boot MongoDB自动删除文档无效
我对MongoDB中的“生存时间”设置有问题。我在Spring Boot 2.0.2.RELEASE项目中的实体中创建了一个索引注释,它表示MongoDB中的文档。我将测试的“expireAfterSeconds”设置为15秒,但MongoDB不会在15秒后删除插入的文档。有人能告诉我我做错了什么吗 这是作为JSON的MongoDB索引:用expireAfterSeconds索引的Spring Boot MongoDB自动删除文档无效,spring,mongodb,spring-boot,spring-mongodb,mongodb-indexes,Spring,Mongodb,Spring Boot,Spring Mongodb,Mongodb Indexes,我对MongoDB中的“生存时间”设置有问题。我在Spring Boot 2.0.2.RELEASE项目中的实体中创建了一个索引注释,它表示MongoDB中的文档。我将测试的“expireAfterSeconds”设置为15秒,但MongoDB不会在15秒后删除插入的文档。有人能告诉我我做错了什么吗 这是作为JSON的MongoDB索引: [ 2, { "createdDateTime" : 1 }, "deleteAt", "AccountServiceDB.Acc
[
2,
{
"createdDateTime" : 1
},
"deleteAt",
"AccountServiceDB.AccountRegistration",
NumberLong(15)
]
这是我的实体:
@Document(collection = "AccountRegistration")
public class UserRegistration {
@Id
private ObjectId _id;
@Indexed(unique = true)
private String username;
@Indexed(unique = true)
private String email;
private String user_password;
@Indexed(name = "deleteAt", expireAfterSeconds = 15)
private Date createdDateTime;
public UserRegistration() {}
public ObjectId get_id() {
return _id;
}
public void set_id(ObjectId _id) {
this._id = _id;
}
}
is解释:“删除过期文档的后台任务每60秒运行一次。因此,在文档过期和后台任务运行之间的时间段内,文档可能会保留在集合中。”这不是答案,您只是说文档可能会超过TTL。如果复制开发人员正在使用的代码,您将看到文档将永远存在,并且永远不会被删除。因此,您的回答实际上对开发人员没有用处,应该是一个评论。嘿,您找到了解决方案吗?我也面临同样的问题:(