问题
As the title describes, I'm trying to change the TTL of a cosmos db table. I couldn't find anything in c#/powershell/arm templates Here is what I'm trying to achieve The only thing I was able to find is the api call that is triggered in azure portal, but I'm wondering if it is safe to use this API directly?
回答1:
In Cosmos DB Table API, Tables are essentially Containers thus you can use Cosmos DB SQL API SDK to manipulate the Table. Here's the sample code to do so:
var cosmosClient = new CosmosClient(CosmosConnectionString);
var database = cosmosClient.GetDatabase(Database);
var container = database.GetContainer("test");
var containerResponse = await container.ReadContainerAsync();
var containerProperties = containerResponse.Resource;
Console.WriteLine("Current TTL on the container is: " + containerProperties.DefaultTimeToLive);
containerProperties.DefaultTimeToLive = 120;//
containerResponse = await container.ReplaceContainerAsync(containerProperties);
containerProperties = containerResponse.Resource;
Console.WriteLine("Current TTL on the container is: " + containerProperties.DefaultTimeToLive);
Console.ReadKey();
来源:https://stackoverflow.com/questions/62550860/is-there-a-way-to-programmatically-change-ttl-on-a-cosmos-db-table