I saw a similar question here but there the OP claims he has a typo.
我在这里看到了一个类似的问题,但OP声称他有一个错字。
mongodb TTL not removing documents
mongodb TTL不删除文件
I don't think I have a typo. I created a collection by inserting 3 documents.
Then I added a TTL index on LastUpdated with expireAfterSecs = 120 seconds.
More then 3-4-5 mins later no documents are deleted.
我不认为我有拼写错误。我通过插入3个文档创建了一个集合。然后我在LastUpdated上添加了一个TTL索引,expireAfterSecs = 120秒。超过3-4-5分钟后,没有文件被删除。
Why is that? What am I doing wrong?
这是为什么?我究竟做错了什么?
[test] 2014-03-26 18:35:35.154 >>> db.test_ttl.getIndexes();
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"ns" : "test.test_ttl",
"name" : "_id_"
},
{
"v" : 1,
"key" : {
"LastUpdated" : 1
},
"ns" : "test.test_ttl",
"name" : "LastUpdated_1",
"expireAfterSecs" : 120
}
]
[test] 2014-03-26 18:35:45.378 >>> db.test_ttl.find();
{
"_id" : ObjectId("5333556a426e7309c6213d19"),
"x" : 1,
"LastUpdated" : ISODate("2014-03-26T22:32:10.628Z")
}
{
"_id" : ObjectId("5333556e426e7309c6213d1a"),
"x" : 2,
"LastUpdated" : ISODate("2014-03-26T22:32:14.976Z")
}
{
"_id" : ObjectId("53335581426e7309c6213d1b"),
"x" : 100,
"LastUpdated" : ISODate("2014-03-26T22:32:33.912Z")
}
[test] 2014-03-26 18:35:50.58 >>> new Date();
ISODate("2014-03-26T22:35:52.819Z")
[test] 2014-03-26 18:35:52.835 >>> new Date();
ISODate("2014-03-26T22:36:03.927Z")
[test] 2014-03-26 18:36:03.927 >>> db.test_ttl.find();
{
"_id" : ObjectId("5333556a426e7309c6213d19"),
"x" : 1,
"LastUpdated" : ISODate("2014-03-26T22:32:10.628Z")
}
{
"_id" : ObjectId("5333556e426e7309c6213d1a"),
"x" : 2,
"LastUpdated" : ISODate("2014-03-26T22:32:14.976Z")
}
{
"_id" : ObjectId("53335581426e7309c6213d1b"),
"x" : 100,
"LastUpdated" : ISODate("2014-03-26T22:32:33.912Z")
}
[test] 2014-03-26 18:36:06.376 >>> new Date();
ISODate("2014-03-26T22:36:07.671Z")
[test] 2014-03-26 18:36:07.671 >>>
[test] 2014-03-26 18:39:32.733 >>> db.test_ttl.find();
{
"_id" : ObjectId("5333556a426e7309c6213d19"),
"x" : 1,
"LastUpdated" : ISODate("2014-03-26T22:32:10.628Z")
}
{
"_id" : ObjectId("5333556e426e7309c6213d1a"),
"x" : 2,
"LastUpdated" : ISODate("2014-03-26T22:32:14.976Z")
}
{
"_id" : ObjectId("53335581426e7309c6213d1b"),
"x" : 100,
"LastUpdated" : ISODate("2014-03-26T22:32:33.912Z")
}
[test] 2014-03-26 18:39:44.355 >>> new Date();
ISODate("2014-03-26T22:39:46.086Z")
[test] 2014-03-26 18:39:46.102 >>>
1 个解决方案
#1
1
OK, never mind. This is also a typo. It's
a typo in the book I am reading (page 114).
好吧,那算了。这也是一个错字。这是我正在阅读的书中的一个错字(第114页)。
http://www.oreilly.com/catalog/errata.csp?isbn=0636920028031
http://www.oreilly.com/catalog/errata.csp?isbn=0636920028031
The correct option is expireAfterSeconds not expireAfterSecs.
So I didn't create the TTL index properly due to this typo.
Realized this 4-5 minutes after asking the question.
正确的选项是expireAfterSeconds not expireAfterSecs。因此,由于这个错字,我没有正确创建TTL索引。在提出问题后4-5分钟就实现了这一点。
#1
1
OK, never mind. This is also a typo. It's
a typo in the book I am reading (page 114).
好吧,那算了。这也是一个错字。这是我正在阅读的书中的一个错字(第114页)。
http://www.oreilly.com/catalog/errata.csp?isbn=0636920028031
http://www.oreilly.com/catalog/errata.csp?isbn=0636920028031
The correct option is expireAfterSeconds not expireAfterSecs.
So I didn't create the TTL index properly due to this typo.
Realized this 4-5 minutes after asking the question.
正确的选项是expireAfterSeconds not expireAfterSecs。因此,由于这个错字,我没有正确创建TTL索引。在提出问题后4-5分钟就实现了这一点。