DP-420 · Question #166
You have an Azure Cosmos DB database that hosts a container named container1. You need to ensure that the items stored in container1 will NOT expire unless their TTL value is set explicitly. What…
The correct answer is D. Set the DefaultTimeToLive property to -1. To ensure items in an Azure Cosmos DB container do not expire unless explicitly set with a Time-to-Live (TTL), you must set the container's DefaultTimeToLive property to -1.
Question
You have an Azure Cosmos DB database that hosts a container named container1. You need to ensure that the items stored in container1 will NOT expire unless their TTL value is set explicitly. What should you do?
Options
- ASet the DefaultTimeToLive property to 0.
- BRemove the DefaultTimeToLive property.
- CSet the DefaultTimeToLive property to null.
- DSet the DefaultTimeToLive property to -1.
How the community answered
(25 responses)- A4% (1)
- C4% (1)
- D92% (23)
Why each option
To ensure items in an Azure Cosmos DB container do not expire unless explicitly set with a Time-to-Live (TTL), you must set the container's `DefaultTimeToLive` property to -1.
Setting `DefaultTimeToLive` to 0 means all items without an explicit TTL will expire immediately after creation, which contradicts the requirement.
Removing the `DefaultTimeToLive` property is ambiguous and might default to items never expiring or relying on an account-level setting, but -1 is the explicit way to disable container-level default TTL.
Setting `DefaultTimeToLive` to `null` is generally not a valid or supported configuration for this property and might lead to an error or undefined behavior.
Setting the `DefaultTimeToLive` property to -1 on a container explicitly disables the default TTL policy for all items within that container. This ensures items will persist indefinitely unless an individual item has its own `ttl` property set to a positive integer, overriding the container's default.
Concept tested: Azure Cosmos DB Time-to-Live (TTL) configuration
Source: https://learn.microsoft.com/azure/cosmos-db/time-to-live
Topics
Community Discussion
No community discussion yet for this question.