正如标题所述,我正在尝试更改 cosmos db 表的 TTL。 我在 c#/powershell/arm 模板中找不到任何内容 这就是我想要实现的目标 我唯一能找到的是在azure门户中触发的api调用,但我想知道直接使用这个API是否安全?
最佳答案
在 Cosmos DB Table 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();
关于azure - 有没有办法以编程方式更改 cosmos db 表上的 TTL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62550860/