0
我在這裏看到了類似的問題,但是在那裏OP聲稱他有一個錯字。MongoDB - TTL索引 - 文檔沒有刪除
mongodb TTL not removing documents
我不認爲我有一個錯字。我通過插入3個文檔創建了一個集合。
然後,我在LastUpdated上添加了一個TTL索引,expireAfterSecs = 120秒。
超過3-4-5分鐘後,沒有文件被刪除。
這是爲什麼?我究竟做錯了什麼?
[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 >>>