Azure-docs: How to set Container Default TTL on Extisting Container with dotnet v3 SDK ?

Created on 6 Nov 2019  Â·  4Comments  Â·  Source: MicrosoftDocs/azure-docs

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

Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Pri2 cosmos-dsvc cxp product-question triaged

All 4 comments

@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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

paulmarshall picture paulmarshall  Â·  3Comments

spottedmahn picture spottedmahn  Â·  3Comments

bdcoder2 picture bdcoder2  Â·  3Comments

Favna picture Favna  Â·  3Comments

jamesgallagher-ie picture jamesgallagher-ie  Â·  3Comments