简体   繁体   English

MongoDB TTL 索引不删除过期记录

[英]MongoDB TTL index does not remove an expired record

I created a TTL index on my collection's created_at field to autoremove document after 30s but after sometime passed (5min later) the document didn't get removed.我在我的集合的created_at字段上创建了一个 TTL 索引,以便在 30 秒后自动删除文档,但经过一段时间后(5 分钟后),文档没有被删除。 I read some related questions and I'm sure there was no typo in my collection.我阅读了一些相关问题,我确信我的收藏中没有错字。 Here is the JSON after running db[collectionName].getIndexes()这是运行db[collectionName].getIndexes()后的 JSON

[
{
    "v" : 2,
    "key" : {
        "_id" : 1
    },
    "name" : "_id_",
    "ns" : "record_db.collectionName"
},
{
    "v" : 2,
    "key" : {
        "created_at" : 1.0
    },
    "name" : "created_at_1",
    "ns" : "record_db.collectionName",
    "expireAfterSeconds" : 30.0
}

] And here is an example document: ] 这是一个示例文档:

{
  "_id" : ObjectId("5fc3823af29f9d9eb1518857"),
  "record_path" : path/to/file,
  "timestamp" : 1606648392,
  "humantime" : "29/11/2020 18:12:58",
  "created_at" : ISODate("2020-11-29T18:12:58.859Z")
}

ISODate("2020-11-29T18:12:58.859Z") not happened yet. ISODate("2020-11-29T18:12:58.859Z") 还没有发生。

 const iso = "2020-11-29T18:12:58.859Z" const date = new Date(iso); console.log(date.toString());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM