mongodb TTL not removing documents

后端 未结 2 1331
没有蜡笔的小新
没有蜡笔的小新 2020-12-10 18:15

I have a simple schema like:

{
    _id: String,      // auto generated
    key: String,      // there is a unique index on this field
    timestamp: Date() /         


        
相关标签:
2条回答
  • 2020-12-10 18:54

    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"
    }
    
    0 讨论(0)
  • 2020-12-10 19:01
    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?

    0 讨论(0)
提交回复
热议问题