Collection TTL doesn't seem to be working

Hello,

I have the following collection defined:

{
  name: "idempotency_key",
  history_days: null,
  ttl_days: 1
}

I haven’t looked at the fauna dashboard in some time nor touched this db/collection in some time on the order of several months. However, when I checked it today, I noticed that the test document was still present in the dashboard. This is the document:

{
  "ref": Ref(Collection("idempotency_key"), "329787945218211910"),
  "ts": 1650769241160000,
  "data": {
    "key": "test",
    "request": {
      "foo": "bar",
      "arbitrary": "json"
    }
  }
}

Why would this document still be present after all this time had elapsed? I haven’t been writing to this collection for several months. Is there something I’m missing here?

As covered in the documentation, removal of documents/collections is handled by a background task, and there is no guarantee that removal actually occurs.

If you need to guarantee that a document/collection has been removed, you need to remove it explicitly.

Hello,

I see that, but the documentation on the document level seems to specify the TTL is respected on read, and will act as if the document was deleted even if it wasn’t yet. Do the collection level TTLs not work that way?

No. ttl_days is not handled in the same fashion as ttl. Only ttl is evaluated during document reads.

Due to the way ttl_days is implemented, it would have some performance impact if it were evaluated for every read, especially for reads involving indexes. As a result, there is a good chance that ttl_days will become deprecated in the future.

We recommend using ttl instead.

Thanks for the clarification. I will do that going forward.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.