{"id":9903,"date":"2025-04-10T17:49:33","date_gmt":"2025-04-11T00:49:33","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/cosmosdb\/?p=9903"},"modified":"2025-04-10T17:49:33","modified_gmt":"2025-04-11T00:49:33","slug":"getting-insights-from-changes-to-items-in-azure-cosmos-db-just-got-easier","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cosmosdb\/getting-insights-from-changes-to-items-in-azure-cosmos-db-just-got-easier\/","title":{"rendered":"Getting insights from changes to items in Azure Cosmos DB just got easier!"},"content":{"rendered":"<p>Azure Cosmos DB\u2019s 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.<\/p>\n<p>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 <a href=\"https:\/\/learn.microsoft.com\/azure\/cosmos-db\/continuous-backup-restore-introduction\">continuous backup<\/a> retention period configured.<\/p>\n<h2>Enable all versions and deletes change feed mode<\/h2>\n<p>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\u2019ll be able to read change feed in all versions and deletes mode!<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2025\/04\/Enable_AllVersionsAndDeletes-1.png\"><img decoding=\"async\" class=\" wp-image-9908 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2025\/04\/Enable_AllVersionsAndDeletes-1-300x139.png\" alt=\"Image Enable AllVersionsAndDeletes\" width=\"891\" height=\"413\" srcset=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2025\/04\/Enable_AllVersionsAndDeletes-1-300x139.png 300w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2025\/04\/Enable_AllVersionsAndDeletes-1-1024x476.png 1024w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2025\/04\/Enable_AllVersionsAndDeletes-1-768x357.png 768w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2025\/04\/Enable_AllVersionsAndDeletes-1.png 1417w\" sizes=\"(max-width: 891px) 100vw, 891px\" \/><\/a><\/p>\n<p>If you prefer programmatic deployments, you can update your Azure Cosmos DB account with the <a href=\"https:\/\/learn.microsoft.com\/cli\/azure\/what-is-azure-cli\">az cli<\/a> or <a href=\"https:\/\/learn.microsoft.com\/azure\/azure-resource-manager\/bicep\/overview?tabs=bicep\">Bicep<\/a>. Here\u2019s an example using the az cli to enable all versions and deletes mode on an existing account.<\/p>\n<ol>\n<li>Create variables with values for your Azure Cosmos DB account.<\/li>\n<\/ol>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\"># Azure Cosmos DB account name\r\n$accountName = \"my-cosmos-db-account-name\"\r\n\r\n# Resource group name for your Azure Cosmos DB account\r\n$resourceGroupName = \"resource-group-with-my-cosmos-db-account \"\r\n\r\n# Subscription id for your Azure Cosmos DB account\r\n$subscriptionId = \"my-subscription-id\"\r\n\r\n# Combine variables to create the accountId for later use\r\n$accountId = \"\/subscriptions\/$subscriptionId\/resourceGroups\/$resourceGroupName\/providers\/Microsoft.DocumentDB\/databaseAccounts\/$accountName\"<\/code><\/pre>\n<ol start=\"2\">\n<li>Create a file named <code>capabilities.json<\/code> with the following content.<\/li>\n<\/ol>\n<pre class=\"prettyprint language-json\"><code class=\"language-json\">{\r\n    \"properties\": {\r\n        \"enableAllVersionsAndDeletesChangeFeed\": true\r\n    }\r\n}<\/code><\/pre>\n<ol start=\"3\">\n<li>Use the az cli to make a REST call enabling all versions and deletes change feed mode on your account.<\/li>\n<\/ol>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">az rest --method PATCH --uri \"https:\/\/management.azure.com$accountId\/?api-version=2024-12-01-preview\" --body @capabilities.json --headers content-type=application\/json<\/code><\/pre>\n<h2>Get Started with the SDKs<\/h2>\n<p>We\u2019ve 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&#8217;re building applications in any of these languages, you can now seamlessly integrate change feed functionality into your projects! Visit the <a href=\"https:\/\/learn.microsoft.com\/azure\/cosmos-db\/nosql\/change-feed-modes?tabs=all-versions-and-deletes#work-with-the-change-feed\">documentation<\/a> for examples of how to read change feed in with each SDK.<\/p>\n<p>Here&#8217;s an example how to read change feed using all versions and deletes mode in Python. The full Python sample can be found on <a href=\"https:\/\/github.com\/allenkim0129\/azure-sdk-for-python\/blob\/main\/sdk\/cosmos\/azure-cosmos\/samples\/change_feed_management.py\">GitHub<\/a>.<\/p>\n<pre class=\"prettyprint language-py\"><code class=\"language-py\"># Initialize CosmosClient\r\ncredential = DefaultAzureCredential()\r\nclient = cosmos_client.CosmosClient(ENDPOINT, credential=credential)\r\n\r\n# Connect to database and container\r\ndb = client.get_database_client(DATABASE_ID)\r\ncontainer = db.get_container_client(CONTAINER_ID)\r\n\r\n# Read all change feed with 'AllVersionsAndDeletes' mode\r\nresponse_iterator = container.query_items_change_feed(mode=\"AllVersionsAndDeletes\")\r\nfor doc in response_iterator:\r\n    print(doc)\r\n\r\n# Save the continuation token for future iterations\r\ncontinuation_token = container.client_connection.last_response_headers['etag']<\/code><\/pre>\n<h2>Learn more<\/h2>\n<ul>\n<li><a href=\"https:\/\/learn.microsoft.com\/azure\/cosmos-db\/nosql\/change-feed-modes?tabs=all-versions-and-deletes#all-versions-and-deletes-change-feed-mode-preview\">Change feed modes in Azure Cosmos DB | Microsoft Learn<\/a><\/li>\n<li><a href=\"https:\/\/learn.microsoft.com\/azure\/cosmos-db\/change-feed\">Working with the change feed &#8211; Azure Cosmos DB | Microsoft Learn<\/a><\/li>\n<li><a href=\"https:\/\/learn.microsoft.com\/azure\/cosmos-db\/nosql\/read-change-feed\">Reading Azure Cosmos DB change feed | Microsoft Learn<\/a><\/li>\n<\/ul>\n<h2 id=\"leave-a-review\"><strong>Leave a review\u00a0<\/strong><\/h2>\n<p>Tell us about your Azure Cosmos DB experience! Leave a review on PeerSpot and we\u2019ll gift you $50.\u202f<a href=\"https:\/\/peerspotdotcom.my.site.com\/proReviews\/?SalesOpportunityProduct=00kPy000004TKXJIA4&amp;productPeerspotNumber=30881&amp;CalendlyAccount=peerspot&amp;CalendlyFormLink=peerspot-product-reviews-ps-gc-vi-sf-50&amp;giftCard=50%22%20\\t%20%22_blank\" target=\"_blank\" rel=\"noopener\">Get started here<\/a>.<\/p>\n<h2 id=\"about-azure-cosmos-db\"><strong>\u00a0<\/strong><strong>About Azure Cosmos DB\u00a0<\/strong><\/h2>\n<p>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\u00a0<a href=\"https:\/\/azure.microsoft.com\/en-us\/services\/cosmos-db\/\" target=\"_blank\" rel=\"noopener\">here<\/a>. To stay in the loop on Azure Cosmos DB updates, follow us on\u00a0<a href=\"https:\/\/twitter.com\/azurecosmosdb\" target=\"_blank\" rel=\"noopener\">X<\/a>,\u00a0<a href=\"https:\/\/www.youtube.com\/channel\/UCxZVmw8Rt_xmTpPIzLRMDkw\" target=\"_blank\" rel=\"noopener\">YouTube<\/a>, and\u00a0<a href=\"https:\/\/www.linkedin.com\/showcase\/azure-cosmos-db\" target=\"_blank\" rel=\"noopener\">LinkedIn<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Azure Cosmos DB\u2019s 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 [&hellip;]<\/p>\n","protected":false},"author":94159,"featured_media":9908,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[14],"tags":[],"class_list":["post-9903","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-core-sql-api"],"acf":[],"blog_post_summary":"<p>Azure Cosmos DB\u2019s 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 [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/posts\/9903","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/users\/94159"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/comments?post=9903"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/posts\/9903\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/media\/9908"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/media?parent=9903"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/categories?post=9903"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/tags?post=9903"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}