manaclan
manaclan

Reputation: 994

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. 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()

[
{
    "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")
}

Upvotes: 0

Views: 70

Answers (1)

Someone Special
Someone Special

Reputation: 13588

ISODate("2020-11-29T18:12:58.859Z") not happened yet.

const iso = "2020-11-29T18:12:58.859Z"

const date = new Date(iso);
console.log(date.toString());

Upvotes: 2

Related Questions