azure - 有没有办法以编程方式更改 cosmos db 表上的 TTL

标签 azure azure-cosmosdb azure-cosmosdb-tables

正如标题所述,我正在尝试更改 cosmos db 表的 TTL。 我在 c#/powershell/arm 模板中找不到任何内容 这就是我想要实现的目标 enter image description here 我唯一能找到的是在azure门户中触发的api调用,但我想知道直接使用这个API是否安全? enter image description here

最佳答案

在 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/

相关文章:

java - 有没有办法利用表(azure-storage)客户端 API 通过 CosmosDb 设置项目级别 TTL(生存时间)?

azure - 嵌套 Java 对象/Json 的 CosmosDb 分区键 (Spring Boot)

c# - 找不到方法 : 'System.Threading.Tasks.Task` 1<Microsoft. Azure.Cosmos.Serialization.HybridRow.Result>

azure - 如何高效读取数据湖文件的元数据

azure - 使用react-native管理azure blob

.net - Azure 资源管理器 .NET SDK,复制 VHD/Blob

c# - 在对 LINQ cosmos db 建模时是否应该创建 "Id"属性?

azure - 检查 az cli 输出以查看是否返回值

azure - 通过 REST API 的 Cosmos DB IN 子句

Azure DocumentDb 一致性级别建议