本文介绍了有没有办法以编程方式更改cosmos db表上的TTL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

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

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 templatesHere is what I'm trying to achieveThe 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?

推荐答案

在Cosmos DB Table API中,表本质上是容器,因此您可以使用Cosmos DB SQL API SDK来操作表.这是执行此操作的示例代码:

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();

这篇关于有没有办法以编程方式更改cosmos db表上的TTL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 18:17