Azure Cosmos DB Javascript SDK

                                                             - from  Zero to Hero series

Azure Cosmos DB Javascript SDK

                                                             - from  Zero to Hero series

                                                             - Episode 1

                                                             - Episode 1

I'm Sajee

 @kokkisajee

www.sajeetharan.dev

const profile = {
  role: "Principal Product Manager",
  experience: { total: 13, dev: 9, pm: 4 },
  passion: ["developer tools", "DX", "databases","Web"],
  community: {
    stackOverflow: { countryRank: 1, globalTop10: ["Azure", "Javascript", "AzureCosmosDB"] },
    titles: ["Google Developer Expert", "Microsoft MVP"],
    contributions: ["open-source", "conference speaking"]
  },
  connect: () => console.log("Interested in web or cloud? Let's talk! πŸš€")
};

console.log(`πŸš€ ${profile.role} | ${profile.experience.total}y experience | Dev ❀️ PM`);
profile.connect();

πŸ‘¨β€πŸŽ¨ Front-End developers ?

πŸ‘¨β€πŸ’» Back-End developers ?

πŸ¦Έβ€β™‚οΈ Something else ? something in between ?

☁️ Cloud developers ?

Who are you?

Today's Goals

πŸ‘Explore Azure Cosmos DB JavaScript SDK

 

πŸ‘Master the fundamentals & get started

 

πŸ‘  Build your first app with the SDK

 

πŸ‘Be ready to ask questions

 

 

The Hero’s Struggle  

We' all Have been there!

Slow Setup: Staring at a database that takes

forever to set up.

 

Performance Issues: Struggling with inconsistent

query performance.

 

Complex SDKs: Wrestling with SDKs that require

a PhD to understand.

Meet Your Sidekick, Azure Cosmos DB AND the JavaScript SDK

Azure Cosmos DB -  Develop AI-powered apps at any

scale  

Guranteed Performance

Flexibility && Security

Elastic scale out of

Storage & Throughput

Operational + Analytical

Fully Managed

Developer friendly

Automation

24/7 uptime

Native AI capability

Azure Cosmos DB Javascript SDK

Fluent API Design

Advanced features

 Enhanced Developer Experience

Fully Opensource

"Build blazing-fast, planet-scale apps with familiar Node.js / Javascript experience"

  • Feedback driven development
  • OSS Development practices
  • Project management via Github
  • Fast and Async
  • Simplified syntax and async iterators
  • New samples
  • Easy setup
  • User friendly Methods
  • Highlights benefits of Typescripts
  • User centric design changes (ex. Diagnostics, Bulk API etc)

Azure Cosmos DB JS SDK powers!

Internal tools :

 

  • Azure Cosmos DB Explorer,
  • Emulator Data Explorer,
  • VS Code Extension for Azure databases

 

Community packages (OSS):  

  • Nestjs - Azure-databases
  • NOSQL studio
  • Hasura GraphQL connector
  • Cosmox

                        

                    

JavaScript SDK Evolution

basic CRUD, Support consistency levels, query metrics etc

documentdb (v1)  

multi-region support, improved performance

@azure/cosmos (v4)

azure-cosmos-js (v2)  

@azure/cosmos (v3)  

improved client constructor, simplified syntax, async iterators, Transition from callback to promises

Request diagnostics, Changefeed , AI (vector search, Full text search), new Bulk API etc

Under the Hood

Under the Hood

REST

API

Gateway

R

R

R

R

Replicas

HTTP

TCP

https://aka.ms/SDK-Connectivity-modes

Key features!

Flexible CRUD Operations  

          -   Works seamlessly in Node.js and browser environments

Efficient Bulk Operations   

         - Support migration scenarios, bulk ingestion

Changefeed Support

          - Listen to document updates 

Advanced Security

           - Supports authentication via MI, RBAC 

Seamless Integrations

           -  Works with Azure functions, Logic apps, other frameworks

Diagnostics Support   

           - Enhanced insights into your client operations,

                    

Prerequisities to get started with JS SDK

Prerequisites βœ…

  • Node.js (LTS version) installed
  • Azure Cosmos DB account (NoSQL API) / Azure Cosmos DB emulator
  • VS Code (or any code editor)

How to get started

1️⃣ Install the SDK:

npm install @azure/cosmos

2️⃣ Initialize Cosmos Client: 

const { CosmosClient } = require("@azure/cosmos");
const client = new CosmosClient("YOUR_CONNECTION_STRING");

2️⃣ Initialize Cosmos Client: 

const { CosmosClient } = require("@azure/cosmos");
const client = new CosmosClient("YOUR_CONNECTION_STRING");

3️⃣ Create a Database & Container:

const { database } = await client.databases.createIfNotExists({ id: "MyDatabase" });
const { container } = await database.containers.createIfNotExists({ id: "MyContainer" });

How to get started

4️⃣ Insert Data:

await container.items.create({ id: "1", name: "Azure Rocks!" });

Let's Code

Build a Todo App

 In 3 MINS

 

Best Practices to Remember

 

πŸ‘Make sure to have the app in same region as azure cosmosdb account

 

πŸ‘Always use the latest version of SDK

 

πŸ‘Use single instance of Cosmos Client /Singleton

 

πŸ‘Enable diagnostic logging in case of failures/latency

Next steps

 

Build apps with latest Javascript SDK and report issues with the tag cosmos

 

We value your feedback : https://aka.ms/azurecosmos-js

 

Join the next episode in this series to learn about Best practices with Javascript SDK

 

Feedback or Questions  , reach out  cosmosdb-js-sdk@microsoft.com

Azure Cosmos DB Zero to Hero

By Sajeetharan Sinnathurai

Azure Cosmos DB Zero to Hero

Azure Cosmos DB javascript SDK

  • 170