{"id":10182,"date":"2025-05-23T15:00:10","date_gmt":"2025-05-23T22:00:10","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/cosmosdb\/?p=10182"},"modified":"2025-05-26T00:31:59","modified_gmt":"2025-05-26T07:31:59","slug":"announcing-general-availability-of-javascript-sdk-v4-for-azure-cosmos-db","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cosmosdb\/announcing-general-availability-of-javascript-sdk-v4-for-azure-cosmos-db\/","title":{"rendered":"Announcing General Availability of JavaScript SDK v4 for Azure Cosmos DB"},"content":{"rendered":"<p>We\u2019re excited to launch version 4 of the Azure Cosmos DB JavaScript SDK! This update delivers major improvements that make it easier and faster to build high-performance apps with the Azure Cosmos DB for NoSQL API. Version 4 is available now and targets Node.js v18 and above, introducing a host of new capabilities, including:<\/p>\n<ul>\n<li>Improved bulk operation support<\/li>\n<li>More flexible and scalable query design<\/li>\n<li>Client-side encryption<\/li>\n<li>Built-in vector and full-text search support<\/li>\n<li>Enhanced diagnostic logging &#8230;and much more.<\/li>\n<\/ul>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2025\/05\/V4BLOG.png\"><img decoding=\"async\" class=\"wp-image-10183 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2025\/05\/V4BLOG.png\" alt=\"V4BLOG image\" width=\"275\" height=\"275\" srcset=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2025\/05\/V4BLOG.png 1024w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2025\/05\/V4BLOG-300x300.png 300w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2025\/05\/V4BLOG-150x150.png 150w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2025\/05\/V4BLOG-768x768.png 768w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2025\/05\/V4BLOG-24x24.png 24w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2025\/05\/V4BLOG-48x48.png 48w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2025\/05\/V4BLOG-96x96.png 96w\" sizes=\"(max-width: 275px) 100vw, 275px\" \/><\/a><\/p>\n<p>Version 4 of the SDK is open source, built entirely in TypeScript, and designed for modern JavaScript development. It offers full support for Promises and the async\/await pattern, enabling clean and efficient coding. The SDK also follows official JavaScript SDK design guidelines to ensure consistency and reliability.<\/p>\n<p>For a complete overview of features, documentation, and code samples, visit the <a href=\"https:\/\/github.com\/Azure\/azure-sdk-for-js\/blob\/main\/sdk\/cosmosdb\/cosmos\/CHANGELOG.md\">JavaScript SDK Change Log<\/a>. Whether upgrading from an earlier version or starting from scratch, it\u2019s the go-to resource for getting up to speed.<\/p>\n<p>This blog highlights some of the most impactful updates in the release\u2014and how they can help accelerate application development with Azure Cosmos DB.<\/p>\n<h2><strong>Latest Enhancements in the JavaScript SDK<\/strong><\/h2>\n<p><strong>Improved Query Control in Azure Cosmos DB JavaScript SDK<\/strong><\/p>\n<p>The Azure Cosmos DB JavaScript SDK introduces a new query pipeline to give developers finer control over query execution and improve transparency.<\/p>\n<p><strong>What\u2019s Changed?<\/strong><\/p>\n<p>Previously, each fetchNext call aimed to return up to maxItemCount results, often triggering multiple partition queries behind the scenes. This caused:<\/p>\n<ul>\n<li><strong>\ud83d\ude80 Higher RU Consumption<\/strong>: The SDK re-queried partitions to meet result guarantees, leading to increased RU charges and potential throttling.<\/li>\n<li><strong>\u23f1\ufe0f Unpredictable Latency<\/strong>: Long-running queries reduced responsiveness and developer control.<\/li>\n<\/ul>\n<p><strong>\ud83c\udd95Benefits of the New Query Pipeline<\/strong><\/p>\n<ul>\n<li><strong>\ud83d\udccc Partition-Level Query Control<\/strong>\nEach fetchNext call now queries up to maxDegreeOfParallelism partitions. If no results are available, it returns an <strong>empty page with RU usage<\/strong>, without querying all partitions.<\/li>\n<li><strong>\ud83d\udcca Granular Resource Tracking<\/strong>\nDevelopers can track RUs after each iteration and decide whether to continue or stop querying\u2014giving more control over costs and performance.<\/li>\n<\/ul>\n<p><strong>\u2699\ufe0f How to Enable It<\/strong><\/p>\n<p>Use the enableQueryControl flag in FeedOptions:<\/p>\n<pre class=\"prettyprint language-js prettyprinted\" tabindex=\"0\"><code class=\"language-js hljs language-javascript\" data-highlighted=\"yes\"><span class=\"hljs-keyword\">const<\/span> <span class=\"hljs-attr\">queryOptions<\/span>: <span class=\"hljs-title class_\">FeedOptions<\/span> = {  \r\n  <span class=\"hljs-attr\">maxDegreeOfParallelism<\/span>: <span class=\"hljs-number\">3<\/span>,  \r\n  <span class=\"hljs-attr\">maxItemCount<\/span>: <span class=\"hljs-number\">10<\/span>,  \r\n  <span class=\"hljs-attr\">enableQueryControl<\/span>: <span class=\"hljs-literal\">true<\/span> <span class=\"hljs-comment\">\/\/ Enables the new query pipeline. Default value is false<\/span>\r\n});  <\/code><\/pre>\n<p><strong>\ud83d\udd0d How It Works<\/strong><\/p>\n<p>When enableQueryControl is true, each fetchNext:<\/p>\n<p>Queries a limited number of partitions (up to maxDegreeOfParallelism).<\/p>\n<ul>\n<li>Returns early with empty results and RU usage if no results are found.<\/li>\n<li><strong>Does not auto-fulfill<\/strong> maxItemCount by scanning all partitions.<\/li>\n<\/ul>\n<p><strong>\ud83d\udd04 Backward Compatibility<\/strong><\/p>\n<p>The flag is <strong>disabled by default<\/strong> (enableQueryControl: false), ensuring existing behavior is preserved.<\/p>\n<p><strong>\ud83d\udced Handling Empty Pages<\/strong><\/p>\n<ul>\n<li>Empty pages \u2260 query complete.<\/li>\n<li>Always check the hasMoreResults flag.<\/li>\n<\/ul>\n<ol>\n<li>If true, more results are available.<\/li>\n<li>Use this flag instead of assuming based on current page results.<\/li>\n<\/ol>\n<h3><strong>Unlocking Efficient Bulk Workloads with the New executeBulkOperations API in the JavaScript SDK<\/strong><\/h3>\n<p>The new executeBulkOperations API in the Azure Cosmos DB JavaScript SDK introduces major improvements for handling bulk workloads. This release addresses previous limitations and delivers powerful enhancements that streamline performance and efficiency at scale. Here\u2019s what\u2019s new:<\/p>\n<ul>\n<li><strong>No More 100-Operation Limit<\/strong>\nThe previous restriction of 100 operations per bulk request has been lifted. Applications can now send a much larger number of operations in a single request, improving throughput and reducing client-side batching overhead.<\/li>\n<li><strong>Operation-Level Retry Mechanism<\/strong>\nWe&#8217;ve introduced a smarter retry strategy that applies retries at the <em>individual operation level<\/em>. Rather than retrying the entire batch when failures occur, each operation is evaluated independently and retried as needed. This results in more resilient and efficient error handling.<\/li>\n<li><strong>Dynamic Congestion Control<\/strong>\nThe SDK now features intelligent per-partition concurrency control. It automatically adjusts the number of concurrent requests based on real-time feedback\u2014scaling up when operations complete successfully and scaling down when throttling (HTTP 429) responses are detected. This ensures optimal performance while respecting throughput limits.<\/li>\n<\/ul>\n<p>These enhancements make the JavaScript SDK&#8217;s bulk support more scalable, fault-tolerant, and adaptive, perfect for high-volume workloads in modern cloud applications.<\/p>\n<p>Follow the sample <a href=\"https:\/\/github.com\/Azure\/azure-sdk-for-js\/blob\/main\/sdk\/cosmosdb\/cosmos\/samples\/v4\/typescript\/src\/ExecuteBulkOperations.ts\">here<\/a> for more details.<\/p>\n<h3><strong>Client-side encryption support<\/strong><strong>\u200b<\/strong><\/h3>\n<p>Azure Cosmos DB now supports <strong>Always Encrypted<\/strong> for Node.js applications, enabling client-side encryption to protect sensitive data before it ever leaves the application. With the Cosmos DB JavaScript SDK, developers can easily encrypt and decrypt specific properties within documents\u2014while keeping encryption keys entirely under their control.<\/p>\n<p>The integration is simple: define a protected data encryption key and apply encryption policies directly in container operations. Here\u2019s a quick \u00a0<a href=\"https:\/\/github.com\/Azure\/azure-sdk-for-js\/blob\/main\/sdk\/cosmosdb\/cosmos\/CHANGELOG.md#client-side-encryption-preview-28760\">example<\/a>!<\/p>\n<p>This feature empowers developers to meet stricter compliance and security requirements, all while maintaining a familiar development experience in Node.js.<\/p>\n<h3><strong>New AI Search Capabilities <\/strong><\/h3>\n<p>The Azure Cosmos DB JavaScript SDK now includes powerful AI-driven features. With built-in support for Vector Search, Full-Text Search for advanced text indexing and querying, and Hybrid Search that combines keyword and vector semantics, developers can seamlessly build intelligent, search-enhanced applications. <a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/cosmos-db\/gen-ai\/full-text-search\">Learn more about Full-Text Search<\/a> and <a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/cosmos-db\/gen-ai\/hybrid-search\">Hybrid Search<\/a>.<\/p>\n<h3><strong>And Much more! <\/strong><\/h3>\n<p>This release introduces key stable enhancements including Partition Merge support, partial hierarchical partition key handling in Change Feed, index metrics, client-side request diagnostics, and additional features to optimize JavaScript applications with Azure Cosmos DB.<\/p>\n<h3><strong>Upgrade to JavaScript SDK v4<\/strong><\/h3>\n<p>Thinking of upgrading to JavaScript SDK v4? Here\u2019s a quick summary of the versions we\u2019ve released so far and the relevant Change Log.<\/p>\n<table>\n<tbody>\n<tr>\n<td>Javascript SDK<\/td>\n<td>Release Date<\/td>\n<td>Package Name<\/td>\n<td>Release notes<\/td>\n<\/tr>\n<tr>\n<td>v1<\/td>\n<td>08\/05\/2015<\/td>\n<td>documentdb<\/td>\n<td><a href=\"https:\/\/github.com\/Azure\/azure-cosmosdb-node\/blob\/master\/changelog.md\">azure-cosmosdb-node\/changelog.md at master \u00b7 Azure\/azure-cosmosdb-node (github.com)\u00a0<\/a><\/td>\n<\/tr>\n<tr>\n<td>v2<\/td>\n<td>08\/08\/2018<\/td>\n<td>azure\/cosmos<\/td>\n<td><a href=\"https:\/\/github.com\/Azure\/azure-cosmos-js\/blob\/master\/changelog.md\">azure-cosmos-js\/changelog.md at master \u00b7 Azure\/azure-cosmos-js (github.com)<\/a><\/td>\n<\/tr>\n<tr>\n<td>v3<\/td>\n<td>20\/08\/2019<\/td>\n<td>azure\/cosmos<\/td>\n<td><a href=\"https:\/\/github.com\/Azure\/azure-cosmos-js\/blob\/master\/changelog.md#300\">azure-cosmos-js\/changelog.md at master \u00b7 Azure\/azure-cosmos-js (github.com)<\/a><\/td>\n<\/tr>\n<tr>\n<td>v4<\/td>\n<td>13\/09\/2023<\/td>\n<td>azure\/cosmos<\/td>\n<td><a href=\"https:\/\/github.com\/Azure\/azure-sdk-for-js\/blob\/main\/sdk\/cosmosdb\/cosmos\/CHANGELOG.md\">azure-sdk-for-js\/sdk\/cosmosdb\/cosmos\/CHANGELOG.md at main \u00b7 Azure\/azure-sdk-for-js (github.com)<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>We recommend upgrading to JavaScript SDK v4 for the best performance, the newest features, and continued long-term support. Look and give it your best shot!<\/p>\n<h2><strong>Get started Azure Cosmos DB JavaScript SDK<\/strong><\/h2>\n<p>It\u2019s alright if you\u2019re completely new to the JavaScript SDK \u2013 follow these three steps to get started fast:<\/p>\n<ol>\n<li>Install the latest\u00a0<a href=\"https:\/\/nodejs.org\/en\/download\">Nodejs<\/a>\u00a0version so you can use the\u00a0<a href=\"https:\/\/www.npmjs.com\/package\/@azure\/cosmos\">SDK<\/a>.<\/li>\n<li>Work through the\u00a0<a href=\"https:\/\/learn.microsoft.com\/azure\/cosmos-db\/nosql\/tutorial-nodejs-web-app\">Quickstart Guide for Javascript SDK v4<\/a>\u00a0which gets you access to the\u00a0<a href=\"https:\/\/www.npmjs.com\/package\/@azure\/cosmos\">Javascript SDK v4 npm package<\/a>\u00a0and walks you through basic Azure Cosmos DB requests.<\/li>\n<li>Read the JavaScript SDK\u00a0<a href=\"https:\/\/learn.microsoft.com\/azure\/cosmos-db\/nosql\/best-practices-javascript\">best practices<\/a>\u00a0\u00a0to optimize the SDK for your application.<\/li>\n<\/ol>\n<p>Then visit the\u00a0<a href=\"https:\/\/github.com\/Azure\/azure-sdk-for-js\/blob\/main\/sdk\/cosmosdb\/cosmos\/CHANGELOG.md#400-2023-09-12\">JavaScript SDK v4 Release Notes<\/a>\u00a0page for the rest of our\u00a0<a href=\"https:\/\/learn.microsoft.com\/azure\/cosmos-db\/nosql\/quickstart-nodejs?tabs=azure-portal%2Cpasswordless%2Cwindows%2Csign-in-azure-cli\">documentation and sample code<\/a>.<\/p>\n<p>Happy coding!<\/p>\n<h2><strong>Leave a review<\/strong><\/h2>\n<p>Tell us about your Azure Cosmos DB experience! Leave a review on PeerSpot and we\u2019ll gift you $50.\u00a0<a id=\"menuros8\" class=\"fui-Link ___1q1shib f2hkw1w f3rmtva f1ewtqcl fyind8e f1k6fduh f1w7gpdv fk6fouc fjoy568 figsok6 f1s184ao f1mk8lai fnbmjn9 f1o700av f13mvf36 f1cmlufx f9n3di6 f1ids18y f1tx3yz7 f1deo86v f1eh06m1 f1iescvh fhgqx19 f1olyrje f1p93eir f1nev41a f1h8hb77 f1lqvz6u f10aw75t fsle3fq f17ae5zn\" title=\"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\" 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\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"Link Get started here\">Get started here<\/a>.<\/p>\n<h2><strong>About Azure Cosmos DB<\/strong><\/h2>\n<p>Azure Cosmos DB is a fully managed and serverless NoSQL and vector database for modern app development, including AI applications. With its SLA-backed speed and availability as well as instant dynamic scalability, it is ideal for real-time NoSQL and MongoDB applications that require high performance and distributed computing over massive volumes of NoSQL and vector data.<\/p>\n<p>To stay in the loop on Azure Cosmos DB updates, follow us on\u00a0<a id=\"menurosb\" class=\"fui-Link ___1q1shib f2hkw1w f3rmtva f1ewtqcl fyind8e f1k6fduh f1w7gpdv fk6fouc fjoy568 figsok6 f1s184ao f1mk8lai fnbmjn9 f1o700av f13mvf36 f1cmlufx f9n3di6 f1ids18y f1tx3yz7 f1deo86v f1eh06m1 f1iescvh fhgqx19 f1olyrje f1p93eir f1nev41a f1h8hb77 f1lqvz6u f10aw75t fsle3fq f17ae5zn\" title=\"https:\/\/twitter.com\/azurecosmosdb\" href=\"https:\/\/twitter.com\/AzureCosmosDB\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"Link X\">X<\/a>,\u00a0<a id=\"menurose\" class=\"fui-Link ___1q1shib f2hkw1w f3rmtva f1ewtqcl fyind8e f1k6fduh f1w7gpdv fk6fouc fjoy568 figsok6 f1s184ao f1mk8lai fnbmjn9 f1o700av f13mvf36 f1cmlufx f9n3di6 f1ids18y f1tx3yz7 f1deo86v f1eh06m1 f1iescvh fhgqx19 f1olyrje f1p93eir f1nev41a f1h8hb77 f1lqvz6u f10aw75t fsle3fq f17ae5zn\" title=\"https:\/\/aka.ms\/azurecosmosdbyoutube\" href=\"https:\/\/aka.ms\/AzureCosmosDBYouTube\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"Link YouTube\">YouTube<\/a>, and\u00a0<a id=\"menurosh\" class=\"fui-Link ___1q1shib f2hkw1w f3rmtva f1ewtqcl fyind8e f1k6fduh f1w7gpdv fk6fouc fjoy568 figsok6 f1s184ao f1mk8lai fnbmjn9 f1o700av f13mvf36 f1cmlufx f9n3di6 f1ids18y f1tx3yz7 f1deo86v f1eh06m1 f1iescvh fhgqx19 f1olyrje f1p93eir f1nev41a f1h8hb77 f1lqvz6u f10aw75t fsle3fq f17ae5zn\" title=\"https:\/\/www.linkedin.com\/company\/azure-cosmos-db\/\" href=\"https:\/\/www.linkedin.com\/company\/azure-cosmos-db\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"Link LinkedIn\">LinkedIn<\/a>.<\/p>\n<p>To quickly build your first database, watch our\u00a0<a href=\"https:\/\/youtube.com\/playlist?list=PLmamF3YkHLoLLGUtSoxmUkORcWaTyHlXp\">Get Started videos<\/a>\u00a0on YouTube and explore ways to\u00a0<a href=\"https:\/\/docs.microsoft.com\/azure\/cosmos-db\/optimize-dev-test\">dev\/test free.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>We\u2019re excited to launch version 4 of the Azure Cosmos DB JavaScript SDK! This update delivers major improvements that make it easier and faster to build high-performance apps with the Azure Cosmos DB for NoSQL API. Version 4 is available now and targets Node.js v18 and above, introducing a host of new capabilities, including: Improved [&hellip;]<\/p>\n","protected":false},"author":80443,"featured_media":10302,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[14],"tags":[],"class_list":["post-10182","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-core-sql-api"],"acf":[],"blog_post_summary":"<p>We\u2019re excited to launch version 4 of the Azure Cosmos DB JavaScript SDK! This update delivers major improvements that make it easier and faster to build high-performance apps with the Azure Cosmos DB for NoSQL API. Version 4 is available now and targets Node.js v18 and above, introducing a host of new capabilities, including: Improved [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/posts\/10182","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\/80443"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/comments?post=10182"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/posts\/10182\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/media\/10302"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/media?parent=10182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/categories?post=10182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/tags?post=10182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}