AzureDevOps CosmosDB使用Runbook或模板无需默认即可启用TTL

时间:2019-07-12 07:47:22

标签: azure-cosmosdb ttl azure-runbook

我需要编辑一个现有的Powershell Runbook,它使用模板在Azure中创建cosmosDb。

我需要在没有默认TTL值的情况下启用TTL,到目前为止,在我发现的示例中始终有一个值,这意味着该值用于删除过期的文档。

如何在不设置默认值的情况下仅启用TTL?

我的参考:https://docs.microsoft.com/en-us/azure/cosmos-db/manage-with-powershell#create-container-unique-key-ttl

1 个答案:

答案 0 :(得分:0)

深入研究Microsoft documentation之后,我找到了包含示例的密钥表:

+-------------+--------------------------------------------------------------------+
| TTL on item |                               Result                               |
+-------------+--------------------------------------------------------------------+
| TTL on container is set to null (DefaultTimeToLive = null)                       |
|                                                                                  |
| ttl = null  | TTL is disabled. The item will never expire (default).             |
| ttl = -1    | TTL is disabled. The item will never expire.                       |
| ttl = 2000  | TTL is disabled. The item will never expire.                       |
|             |                                                                    |
+-------------+--------------------------------------------------------------------+
| TTL on container is set to -1 (DefaultTimeToLive = -1)                           |                                                                                  |
|                                                                                  |
| ttl = null  | TTL is enabled. The item will never expire (default).              |
| ttl = -1    | TTL is enabled. The item will never expire.                        |
| ttl = 2000  | TTL is enabled. The item will expire after 2000 seconds.           |
|             |                                                                    |
+-------------+--------------------------------------------------------------------+
| TTL on container is set to 1000 (DefaultTimeToLive = 1000)                                          |
|                                                                                  |
| ttl = null  | TTL is enabled. The item will expire after 1000 seconds (default). |
| ttl = -1    | TTL is enabled. The item will never expire.                        |
| ttl = 2000  | TTL is enabled. The item will expire after 2000 seconds.           |
+-------------+--------------------------------------------------------------------+

这与Runbook和模板不完全相同,但是如果我设置为-1,我可以实现我的意图,如上表所示,在容器中设置TTL -1,将启用该功能,并且在文件将被使用。

使用Get-Help New-CosmosDbCollection -full可以找到参数-DefaultTimeToLive,这就是我要使用的参数,因为在ARM Template中似乎没有选择可以使用它