azure-cosmosdbttl

Azure cosmosDB does not delete documents with expired TTL


I have a collection in an Azure cosmosDB, where I enabled the Time To Live (TTL) feature with no defaults.

As per the documentation, which I will refer to in this question, everything seems crystal clear but there is still something I am missing, because after 5 days I still can see documents with a TTL of 300 seconds.

Below the screenshot showing the collection settings, where the TTL is enabled with no default. enter image description here

According with the documentation:

Azure Cosmos DB will automatically remove these items after the time period, since the time they were last modified. Time to live value is configured in seconds. When you configure TTL, the system will automatically delete the expired items based on the TTL value, without needing a delete operation that is explicitly issued by the client application.

But this doesn't seem to apply in my case, where on the 17/07/2019 I can see a document oder than 5 days, using a TTL of 300 seconds (5 minutes).

{
    "ClientEnqueuedUtcTime": "2019-07-12T06:49:53.844",
    "ClientDispatchedUtcTime": "2019-07-12T06:49:53.844",
    "ServerEnqueuedUtcTime": "2019-07-12T06:49:53.8949771",
    "ServerDispatchedUtcTime": "2019-07-12T06:49:54.3659741",
    "TTL": 300,
    "EventProcessedUtcTime": "2019-07-12T06:49:55.3583521Z",
    "PartitionId": 2,
    "EventEnqueuedUtcTime": "2019-07-12T06:49:55.25Z",
    "id": "4a0edf24-6a86-4a59-f55d-d7dfe47c30fa",
    "_rid": "SBk4AJadUE6gAgEAAAAAAA==",
    "_self": "dbs/SBk4AA==/colls/SBk4AJadUE4=/docs/SBk4AJadUE6gAgEAAAAAAA==/",
    "_etag": "\"00008f1d-0000-0200-0000-5d282d930000\"",
    "_attachments": "attachments/",
    "_ts": 1562914195
}

UPDATE After the answer

I tried to salve the TTL in lower case format, but it was transformed uppercase automatically, so I don't think it is a case mismatch with the expected TTL key.

Am I supposed to do or try anything else?

SOLUTION:

ttl is indeed case sensitive, and you can set it lowercase, in the test I done for some reason the ttl was still uppercase, when I was expecting it to be lower, so I tough incorrectly that was some kind of reserved key.


Solution

  • As you can see here it is the case of the property that causes this to not work.

    It needs to be lowercase. I just tested with both TTL and ttl and indeed the first one doesn't work but the second does work as stated in the documentation. It might be your Json serializer that's forcing it to go uppercase.

    You can use the JsonProperty attribute to force the case of the property to lowercase. Here is an example of the ttl property from Microsoft's documentation.

    
        // Include a property that serializes to "ttl" in JSON
        public class SalesOrder
        {
            [JsonProperty(PropertyName = "id")]
            public string Id { get; set; }
            [JsonProperty(PropertyName="cid")]
            public string CustomerId { get; set; }
            // used to set expiration policy
            [JsonProperty(PropertyName = "ttl", NullValueHandling = NullValueHandling.Ignore)]
            public int? ttl { get; set; }
    
            //...
        }