Azure 有没有一种方法可以通过编程方式更改cosmos db表上的TTL

Azure 有没有一种方法可以通过编程方式更改cosmos db表上的TTL,azure,azure-cosmosdb,azure-cosmosdb-tables,Azure,Azure Cosmosdb,Azure Cosmosdb Tables,正如标题所描述的,我正在尝试更改cosmos db表的TTL。 我在c#/powershell/arm模板中找不到任何内容 这就是我想要实现的目标 我唯一能找到的是azure portal中触发的api调用,但我想知道直接使用此api是否安全? 在Cosmos DB Table API中,表本质上是容器,因此您可以使用Cosmos DB SQL API SDK来操作表。下面是执行此操作的示例代码: var cosmosClient = new CosmosClient(CosmosCon

正如标题所描述的,我正在尝试更改cosmos db表的TTL。 我在c#/powershell/arm模板中找不到任何内容 这就是我想要实现的目标 我唯一能找到的是azure portal中触发的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();

通过
Microsoft.Azure.Cosmos.Table直接使用版本>=1.0.8.

// Get the table reference for table operations
CloudTable table = <tableClient>.GetTableReference(<tableName>);

table.CreateIfNotExists(defaultTimeToLive: <ttlInSeconds>);
//获取表操作的表引用
CloudTable=.GetTableReference();
table.CreateIfNotExists(defaultTimeToLive:);

您应该可以使用任何可用的Cosmos DB SDK来实现这一点。我已经在Azure portal中的Cosmos表上测试了设置TTL,它确实可以工作,并且比我设置的TTL更高的行会自动删除。所以我不知道你为什么说它没有影响。它可以让你在表上设置TTL,但据我(Cosmos DB团队)所知,一旦TTL过期,实体将不会自动删除。您是否看到实体自动从表中删除?是的,它们正在删除!我被告知不是这样。很高兴知道这一点。让我联系Cosmos DB团队,寻求澄清。@SayantanGhosh…请不要在评论中提问。而是提出一个新问题,并在那里提供所有相关细节。