mongodb TTL not removing documents

≡放荡痞女 提交于 2019-11-28 11:29:48
  1. Can you show us what the inserted records actually look like?

  2. How long is "never"? Because there's a big warning:

    Warning: The TTL index does not guarantee that expired data will be deleted immediately. There may be a delay between the time a document expires and the time that MongoDB removes the document from the database.

  3. Does the timestamp field have an index already?

This was my issue: I had the index created wrong like this:

{
    "v" : 1,
    "key" : {
        "columnName" : 1,
        "expireAfterSeconds" : 172800
    },
    "name" : "columnName_1_expireAfterSeconds_172800",
    "ns" : "dbName.collectionName"
}

When it should have been this: (expireAfterSeconds is a top level propery)

{
    "v" : 1,
    "key" : {
        "columnName" : 1
    },
    "expireAfterSeconds" : 172800,
    "name" : "columnName_1_expireAfterSeconds_172800",
    "ns" : "dbName.collectionName"
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!