Skip to main content Explore View all products (200+) Microsoft Foundry Azure Copilot GitHub Copilot Azure Kubernetes Service (AKS) Azure Cosmos DB Azure Database for PostgreSQL Azure Arc Microsoft Fabric Linux virtual machines in Azure Foundry Models Foundry Agent Service Foundry IQ Foundry Tools Foundry Control Plane Observability in Foundry Control Plane Azure OpenAI in Foundry Models Azure Speech in Foundry Tools Azure Machine Learning View all databases Azure Cosmos DB Azure DocumentDB Azure SQL Azure Database for PostgreSQL Azure Managed Redis Microsoft Fabric Azure Databricks Linux virtual machines in Azure Windows Server on Azure Azure Functions Azure Virtual Machine Scale Sets Azure API Management Azure Container Apps Azure Kubernetes Service (AKS) Azure Kubernetes Fleet Manager Azure Container Registry Azure Red Hat OpenShift Azure Container Instances Azure Container Storage Azure Arc Azure Local Microsoft Defender for Cloud Azure Monitor Microsoft Sentinel Azure Migrate View all solutions (40+) Cloud solutions for small and medium businesses Cloud migration and modernization center Data analytics for AI Azure Databases AI apps and agents Microsoft Marketplace Microsoft Sovereign Cloud AI apps and agents Responsible AI with Azure AI Infrastructure Data analytics for AI Machine learning operations (MLOps) Low-code application development on Azure Integration Services Serverless computing DevOps Migration and modernization center .NET apps migration Databases on Azure Linux on Azure Oracle on Azure SAP on the Microsoft Cloud Adaptive cloud High-performance computing (HPC) Infrastructure as a service (IaaS) Resiliency Azure Essentials Frontier Accelerate for Azure FinOps on Azure Microsoft Marketplace Azure pricing overview Create an Azure account Free Azure services Flexible purchase options Pricing calculator FinOps on Azure Maximize ROI from AI Azure savings plans Azure reservations Azure Hybrid Benefit Virtual Machines Azure SQL Microsoft Foundry Microsoft Fabric Azure Kubernetes Service (AKS) Microsoft Defender for Cloud View more Software Development Companies Microsoft Marketplace Find a partner Resources for Azure partners Get started with Azure Customer stories Analyst reports, white papers, and e-books Videos Learn more about cloud computing Documentation Explore Azure portal Developer resources Quickstart templates Resources for startups Developer community Students Azure for partners Blog Events and Webinars Learn Support Contact Sales Get started with Azure Sign in

Azure DocumentDB is making it easy to prune old data with the support for Time To Live (TTL). 

Previously, if you wanted to delete documents in DocumentDB older than a particular point in time, you would have to write your own logic to first retrieve the records, and then execute a delete statement per document in the result set. You would have to schedule and run this logic in some custom process like an Azure worker role, or use a custom built activity within Azure Data Factory. This custom logic would consume Request Units for fetching the documents and again for each delete operation, making this a potentially very costly exercise. 

With the addition of “time to live” or TTL, Azure DocumentDB provides the ability to store data and with the ability to have that data automatically purged from the system. By setting the “ttl”  property of a document, customers can control exactly when documents will be automatically purged by the service. This expiry time interval can be set at a collection level or at an individual document level. Once this TTL value is set, either at the collection or document level, DocumentDB will automatically remove documents that were modified at a time older than the TTL value. For example, a TTL value of 1000 would automatically delete a document modified more than 1000 seconds ago.

In addition to simplifying the process of purging old data, TTL also makes capacity planning easy. Purges caused by TTL expiration are not charged RUs out of the user’s provisioned budget. This means that you don’t need to plan your provisioned throughput around nightly delete jobs or the like.

TTL values can be set at the collection and the document levels. The collection level TTL controls whether TTL enforcement is enabled for the data in that collection and if so, what the default TTL is. The document level TTL enables you to either selectively enable TTL on a per-document basis or override the collection level default. Disabling enforcement at the collection level prevents any documents from being purged due to TTL expiration. This is to ensure that in case documents need to be retained (Eg: incorrect TTLs are accidentally written to documents), this can be achieved in a single operation instead of having to update every document in the collection.

DocumentDB TTL documentation describes this feature in detail – you can start using this on your existing and new DocumentDB accounts today.

To learn more about DocumentDB, visit the DocumentDB product page. If you need any help or have questions or feedback, please reach out to us on the developer forums on Stack Overflow or schedule a 1:1 chat with the DocumentDB engineering team.

Stay up-to-date on the latest DocumentDB news and features by following us on Twitter @DocumentDB.

WE ARE MICROSOFT

Explore Microsoft Foundry

The future of AI starts here. Envision your next great AI app with the latest technologies. Get started with Azure.