如标题所述,我正在尝试更改 cosmos db 表的 TTL。我在 c#/powershell/arm 模板中找不到任何东西这是我想要实现
的唯一我能找到的是在 azure 门户中触发的 api 调用,但我想知道它是否安全直接使用这个API?
问问题
717 次
2 回答
2
在 Cosmos DB 表 API 中,表本质上是容器,因此您可以使用 Cosmos DB SQL API SDK 来操作表。这是执行此操作的示例代码:
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();
于 2020-06-24T09:18:40.290 回答
0
现在Microsoft.Azure.Cosmos.Table
直接通过版本 >= 1.0.8 支持设置 TTL。
// Get the table reference for table operations
CloudTable table = <tableClient>.GetTableReference(<tableName>);
table.CreateIfNotExists(defaultTimeToLive: <ttlInSeconds>);
于 2020-08-28T05:03:34.907 回答