Condividi tramite


DocumentCollection.DefaultTimeToLive Property

Definition

Gets the default time to live in seconds for documents in a collection from the Azure Cosmos DB service.

[Newtonsoft.Json.JsonProperty(NullValueHandling=Newtonsoft.Json.NullValueHandling.Ignore, PropertyName="defaultTtl")]
public int? DefaultTimeToLive { get; set; }
[<Newtonsoft.Json.JsonProperty(NullValueHandling=Newtonsoft.Json.NullValueHandling.Ignore, PropertyName="defaultTtl")>]
member this.DefaultTimeToLive : Nullable<int> with get, set
Public Property DefaultTimeToLive As Nullable(Of Integer)

Property Value

It is an optional property. A valid value must be either a nonzero positive integer, '-1', or null. By default, DefaultTimeToLive is set to null meaning the time to live is turned off for the collection. The unit of measurement is seconds. The maximum allowed value is 2147483647.

Attributes
Newtonsoft.Json.JsonPropertyAttribute

Examples

The example below disables time-to-live on a collection.

collection.DefaultTimeToLive = null;

The example below enables time-to-live on a collection. By default, all the documents never expire.

collection.DefaultTimeToLive = -1;

The example below enables time-to-live on a collection. By default, the document will expire after 1000 seconds since its last write time.

collection.DefaultTimeToLive = 1000;

Remarks

The DefaultTimeToLive will be applied to all the documents in the collection as the default time-to-live policy. The individual document could override the default time-to-live policy by setting its TimeToLive.

When the DefaultTimeToLive is null, the time-to-live will be turned off for the collection. It means all the documents will never expire. The individual document's TimeToLive will be disregarded.

When the DefaultTimeToLive is '-1', the time-to-live will be turned on for the collection. By default, all the documents will never expire. The individual document could be given a specific time-to-live value by setting its TimeToLive. The document's TimeToLive will be honored, and the expired documents will be deleted in background.

When the DefaultTimeToLive is a nonzero positive integer, the time-to-live will be turned on for the collection. And a default time-to-live in seconds will be applied to all the documents. A document will be expired after the specified DefaultTimeToLive value in seconds since its last write time. The individual document could override the default time-to-live policy by setting its TimeToLive. Please refer to the TimeToLive for more details about evaluating the final time-to-live policy of a document.

Applies to

See also