[英]Programmatically verify whether TTL enabled on Cosmos DB collections
[英]Is there a way to programmatically change TTL on a cosmos db Table
In Cosmos DB Table API, Tables are essentially Containers thus you can use Cosmos DB SQL API SDK to manipulate the Table. 这是执行此操作的示例代码:
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();
现在支持通过Microsoft.Azure.Cosmos.Table
直接设置 TTL,版本 >= 1.0.8。
// Get the table reference for table operations
CloudTable table = <tableClient>.GetTableReference(<tableName>);
table.CreateIfNotExists(defaultTimeToLive: <ttlInSeconds>);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.