[英]Java Spring Boot embedded MongoDB doesn't trigger TTL removal
I am trying to test MongoDB TTL functionality for short-lived collections.我正在尝试为短暂的 collections 测试 MongoDB TTL 功能。 Using @Indexed annotation on field like this:
在字段上使用 @Indexed 注释,如下所示:
@Indexed(name = "deleteAt", expireAfterSeconds = 5)
private Date deleteAt;
In constructor I initialise deleteAt to this.deleteAt = new Date()
and I expect after inserting my Document to Mongo that after it's TTLManager will run this collection will be removed.在构造函数中,我将 deleteAt 初始化为
this.deleteAt = new Date()
,并且我希望在将我的 Document 插入 Mongo 之后,在它的 TTLManager 运行之后,这个集合将被删除。 But It is not being removed even waiting for a few minutes doesn't help.但是即使等待几分钟也没有帮助它没有被删除。 I ran
db.serverStatus().metrics.ttl
in mongo shell and it returned:我在 mongo shell 中运行
db.serverStatus().metrics.ttl
并返回:
[
{
"deletedDocuments": 0,
"passes": 8
}
]
And command db.adminCommand({getParameter:1, ttlMonitorEnabled: 1})
returns:并且命令
db.adminCommand({getParameter:1, ttlMonitorEnabled: 1})
返回:
[
{
"ok": 1,
"ttlMonitorEnabled": true
}
]
Is something wrong with my code?我的代码有问题吗? Or it is because of embedded mongo doesn't support this, is it possible to configure embedded mongo so it would work?
或者是因为嵌入式 mongo 不支持这一点,是否可以配置嵌入式 mongo 使其工作? I am using https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo for embedded MongoDB with default settings.
我正在使用https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo用于嵌入式 MongoDB 和默认设置。
It's only MongoDB server ( mongod
) feature它只是 MongoDB 服务器(
mongod
)功能
A background thread in
mongod
reads the values in the index and removes expired documents from the collection.mongod
中的后台线程读取索引中的值并从集合中删除过期文档。
https://docs.mongodb.com/manual/core/index-ttl/#delete-operations https://docs.mongodb.com/manual/core/index-ttl/#delete-operations
Embedded MongoDB framework "simulates" mongod
process with MongodProcess
class only to deploy a basic embedded server.嵌入式 MongoDB 框架使用
MongodProcess
class “模拟” mongod
进程,仅用于部署基本的嵌入式服务器。
https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo/blob/master/src/main/java/de/flapdoodle/embed/mongo/MongodProcess.java https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo/blob/master/src/main/java/de/flapdoodle/embed/mongo/MongodProcess.java
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.