Search code examples
c#.netazureazure-storageazure-cosmosdb

Azure Cosmos DB Set collection TTL as - on (No Default) via C# code


I am looking for an option to set my Cosmos DB collection TTL to ON but with no default.

Here I want to control expiry time at the document level. I see if I set default Time in collection level it will override the time mentioned in document level. Correct me if I am wrong.

Basically, I can set this in Data Explorer but not sure how I can set up through C# code.

From this https://learn.microsoft.com/en-us/azure/cosmos-db/time-to-live,

I see I can set -1 (Expiry off) or n for a number of seconds for expiry.

enter image description here


Solution

  • So just to clarify.

    • When DefaultTimeToLive is null then your Time to Live is Off
    • When DefaultTimeToLive is -1 then your Time to Live setting is On (No default)
    • When DefaultTimeToLive has any other Int value (except 0) your Time to Live setting is On