WHAT IS AZURE COSMOS DB?
Azure Cosmos DB is a distributed, fully managed NoSQL and relational database solution made for contemporary app development. It supports open-source databases including PostgreSQL, MongoDB, and Apache Cassandra2 and provides high performance and high availability
USE CASES
Azure Cosmos DB is a flexible database solution that can be applied to many different situations. These are a few such usage cases:
Telematics and the Internet of Things (IoT): Azure Cosmos DB can manage the enormous volumes of data produced by IoT devices, offering real-time analytics and insights.
Retail and Marketing: It is widely used to manage product catalogues, customer information, and transaction histories in e-commerce platforms.
Gaming: To ensure low-latency access and high availability, game creators store player data, game state, and leaderboards using Azure Cosmos DB.
Web and Mobile Applications: It supports apps like social media platforms, content management systems, and real-time analytics that need quick and scalable data storage.
SETTING UP AZURE COSMOS DB ACCOUNT
Go to search bar in your Azure portal and type “cosmos”
Click on Azure Cosmos DB in the list of returned results
- Click on Create
- Choose the "Core (SQL)" API.
- Provide the necessary details like the resource group, account name, and region.
- Click "Review + Create".
- Once validation success displays, click "Create"
- Click “Go to resource“ and explore your Cosmos DB
CONNECT TO YOUR COSMOS DB ACCOUNT
On the left pane in your Cosmos DB, locate the Quick start blade
In the Choose a platform section, click on Node.js tab
in the Add a container list, click on Create ‘items‘ container. The item is created automatically
Click on Download in number 2 on the list
Watch the top right on your screen and click on open folder to locate the zip file on your local computer. Extract the contents of the zip file.
NB: If at this point you don’t have Visual Studio Code installed on your computer, download and install via this link: https://code.visualstudio.com/download. Also, download Nodejs if you haven’t done so before now. Here is the link: https://nodejs.org/en
Refer to …
Click Open data explorer to work with your data.
- Open Visual Studio Code
- Click on Open folder from the File menu
- Locate the folder of the extracted zip file you downloaded from Azure cosmos DB Choose the file and click Select folder. Refer to 5
- Click on Yes, I trust the authors and close the window page
- Take note of the contents in the folder on the left pane of VS Code and open a new terminal
- Run the following command on the terminal. npm install and npm start
NB: If you are getting error messages, make sure you are in the directory where the package,json file is using the cd - change directory command.
cd C:\Users\Kadex\Downloads\DocumentDB-Quickstart-Node\sql-nodejs\sql-nodejs
- Go back to the Azure portal and click on the keys blade under settings
- Confirm that the URI is the same with what you have in the config.js file.
This shows that Azure Cosmos DB has automatically connected to your Azure Cosmos DB account upon running the npm install command
You can go ahead to create items by clicking on Data Explorer on the left pane
NB: You can also run SQL commands on the Azure Cosmos DB. Other APIs don’t use SQL commands.
Click on New SQL Query
The arrow at the top points to the area to write your code, the area below shows the result of your code and returns error if syntax is not correct.
Use the Execute Query to run your codes.