April 10th, 2025

Getting insights from changes to items in Azure Cosmos DB just got easier!

Justine Cocchi
Senior Program Manager

Azure Cosmos DB’s change feed provides a view of changes to data in your container. This enables patterns like event sourcing, auditing and synchronizing downstream systems. Change feed can be read in real time or on demand, giving you the most flexibility for processing and reprocessing changes.

Change feed is available in two modes, latest version mode and all versions and deletes mode. The all versions and deletes mode Public Preview is now easier to use and you can enable it directly on your accounts without registering your subscription! Latest version mode gives you changes from create and update operations, while all versions and deletes mode gives you these changes in addition to changes from delete operations. It also provides metadata to identify if a given change is from a create, update or delete. With all versions and deletes change feed mode, you can read every change that occurred in your container within the continuous backup retention period configured.

Enable all versions and deletes change feed mode

In your Azure Cosmos DB account, navigate to the Features page to enable the all versions and deletes change feed mode Public Preview. Before enabling, ensure your account has turned on continuous backups. The enablement process can take up to 30 minutes, after which you’ll be able to read change feed in all versions and deletes mode!

Image Enable AllVersionsAndDeletes

If you prefer programmatic deployments, you can update your Azure Cosmos DB account with the az cli or Bicep. Here’s an example using the az cli to enable all versions and deletes mode on an existing account.

  1. Create variables with values for your Azure Cosmos DB account.
# Azure Cosmos DB account name
$accountName = "my-cosmos-db-account-name"

# Resource group name for your Azure Cosmos DB account
$resourceGroupName = "resource-group-with-my-cosmos-db-account "

# Subscription id for your Azure Cosmos DB account
$subscriptionId = "my-subscription-id"

# Combine variables to create the accountId for later use
$accountId = "/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.DocumentDB/databaseAccounts/$accountName"
  1. Create a file named capabilities.json with the following content.
{
    "properties": {
        "enableAllVersionsAndDeletesChangeFeed": true
    }
}
  1. Use the az cli to make a REST call enabling all versions and deletes change feed mode on your account.
az rest --method PATCH --uri "https://management.azure.com$accountId/?api-version=2024-12-01-preview" --body @capabilities.json --headers content-type=application/json

Get Started with the SDKs

We’ve also recently added support for all versions and deletes mode in more SDKs! The .NET, Java, Python and JavaScript SDKs all provide APIs for using all versions and deletes change feed mode. Whether you’re building applications in any of these languages, you can now seamlessly integrate change feed functionality into your projects! Visit the documentation for examples of how to read change feed in with each SDK.

Here’s an example how to read change feed using all versions and deletes mode in Python. The full Python sample can be found on GitHub.

# Initialize CosmosClient
credential = DefaultAzureCredential()
client = cosmos_client.CosmosClient(ENDPOINT, credential=credential)

# Connect to database and container
db = client.get_database_client(DATABASE_ID)
container = db.get_container_client(CONTAINER_ID)

# Read all change feed with 'AllVersionsAndDeletes' mode
response_iterator = container.query_items_change_feed(mode="AllVersionsAndDeletes")
for doc in response_iterator:
    print(doc)

# Save the continuation token for future iterations
continuation_token = container.client_connection.last_response_headers['etag']

Learn more

Leave a review 

Tell us about your Azure Cosmos DB experience! Leave a review on PeerSpot and we’ll gift you $50. Get started here.

 About Azure Cosmos DB 

Azure Cosmos DB is a fully managed and serverless distributed database for modern app development, with SLA-backed speed and availability, automatic and instant scalability, and support for open-source PostgreSQL, MongoDB, and Apache Cassandra. Try Azure Cosmos DB for free here. To stay in the loop on Azure Cosmos DB updates, follow us on XYouTube, and LinkedIn.

Author

Justine Cocchi
Senior Program Manager

Justine is a Program Manager on the Azure Cosmos DB team working on various aspects of the SQL API.

0 comments