The docs here describe how to set the default TTL when creating a container via the dotnet SDK (v3).
However I can't find any documentation on how to change the default TTL after the collection has been created. I cant find a DefaultTimeToLive property or a ContainerProperties property on the C# objects.
I expected to be able to do something like this:
var options = new MyCosmosOptions();
var client = new CosmosClient(options.Endpoint, options.PrimaryKey);
var container = client.GetContainer(options.Database, containerName);
container.SetDefaultTimeToLive(60); // no method like this exists afaik
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
@xtellurian We are checking this and will get back to you.
@xtellurian Please try the below snippet to enable TTL on an existing container.
```cs
var containerResponse = await simpleContainer.ReadContainerAsync();
ContainerProperties containerProperties = containerResponse;
containerProperties.DefaultTimeToLive = (int)TimeSpan.FromDays(1).TotalSeconds; //expire in 1 day
var containerResponseWithTTLEnabled = simpleContainer.ReplaceContainerAsync(containerProperties);
`
@KalyanChanumolu-MSFT that appears to work, thanks :)
This could be a useful thing to include in the docs.
@xtellurian Thank you for the suggestion.
Let me see if I can add it to the documentation. If not I will add it to the Code Samples here
We will proceed to close this issue now.
If there are further questions regarding this matter, please comment and we will gladly continue the discussion.