1599087060
In this video, watch how fast and easy it is to leverage the Spring framework and Spring Initializr to create a Maven project to connect to Azure Cosmos DB via the Spring Mongo DB dependency package.
#spring
1624713540
This article is a part of the series – Learn NoSQL in Azure where we explore Azure Cosmos DB as a part of the non-relational database system used widely for a variety of applications. Azure Cosmos DB is a part of Microsoft’s serverless databases on Azure which is highly scalable and distributed across all locations that run on Azure. It is offered as a platform as a service (PAAS) from Azure and you can develop databases that have a very high throughput and very low latency. Using Azure Cosmos DB, customers can replicate their data across multiple locations across the globe and also across multiple locations within the same region. This makes Cosmos DB a highly available database service with almost 99.999% availability for reads and writes for multi-region modes and almost 99.99% availability for single-region modes.
In this article, we will focus more on how Azure Cosmos DB works behind the scenes and how can you get started with it using the Azure Portal. We will also explore how Cosmos DB is priced and understand the pricing model in detail.
As already mentioned, Azure Cosmos DB is a multi-modal NoSQL database service that is geographically distributed across multiple Azure locations. This helps customers to deploy the databases across multiple locations around the globe. This is beneficial as it helps to reduce the read latency when the users use the application.
As you can see in the figure above, Azure Cosmos DB is distributed across the globe. Let’s suppose you have a web application that is hosted in India. In that case, the NoSQL database in India will be considered as the master database for writes and all the other databases can be considered as a read replicas. Whenever new data is generated, it is written to the database in India first and then it is synchronized with the other databases.
While maintaining data over multiple regions, the most common challenge is the latency as when the data is made available to the other databases. For example, when data is written to the database in India, users from India will be able to see that data sooner than users from the US. This is due to the latency in synchronization between the two regions. In order to overcome this, there are a few modes that customers can choose from and define how often or how soon they want their data to be made available in the other regions. Azure Cosmos DB offers five levels of consistency which are as follows:
In most common NoSQL databases, there are only two levels – Strong and Eventual. Strong being the most consistent level while Eventual is the least. However, as we move from Strong to Eventual, consistency decreases but availability and throughput increase. This is a trade-off that customers need to decide based on the criticality of their applications. If you want to read in more detail about the consistency levels, the official guide from Microsoft is the easiest to understand. You can refer to it here.
Now that we have some idea about working with the NoSQL database – Azure Cosmos DB on Azure, let us try to understand how the database is priced. In order to work with any cloud-based services, it is essential that you have a sound knowledge of how the services are charged, otherwise, you might end up paying something much higher than your expectations.
If you browse to the pricing page of Azure Cosmos DB, you can see that there are two modes in which the database services are billed.
Let’s learn about this in more detail.
#azure #azure cosmos db #nosql #azure #nosql in azure #azure cosmos db
1626494129
Last month, the Azure SDK team released a new library for Azure Tables for .NET, Java, JS/TS and Python. This release brings the Table SDK in line with other Azure SDKs and they use the specific Azure Core packages for handling requests, errors and credentials.
Azure Cosmos DB provides a Table API offering that is essentially Azure Table Storage on steroids! If you need a globally distributed table storage service, Azure Cosmos DB should be your go to choice.
If you’re making a choice between Azure Cosmos DB Table API and regular Azure Table Storage, I’d recommend reading the following article.
In this article, I’ll show you how we can perform simple operations against a Azure Cosmos DB Table API account using the new Azure.Data.Table C## SDK. Specifically, we’ll go over:
Let’s dive into it!
Installing the SDK is pretty simple. We can do so by running the following dotnet command:
dotnet add package Azure.Data.Tables
If you prefer using a UI to install the NuGet packages, we can do so by right-clicking our C## Project in Visual Studio, click on Manage NuGet packages and search for the Azure.Data.Tables package:
The SDK provides us with two clients to interact with the service. A TableServiceClient is used for interacting with our table at the account lelvel.
We do this for creating tables, setting access policies etc.
We can also use a TableClient. This is used for performing operations on our entities. We can also use the TableClient to create tables like so:
TableClient tableClient = new TableClient(config["StorageConnection"], "Customers");
await tableClient.CreateIfNotExistsAsync();
To create our Table Client, I’m passing in my storage connection string from Azure and the name of the table I want to interact with. On the following line, we create the table if it doesn’t exist.
To get out Storage Connection string, we can do so from our Cosmos DB account under Connection String:
When we run this code for the first time, we can see that the table has been created in our Data Explorer:
In Table Storage, we create entities in our table that require a Partition Key and a Row Key. The combination of these need to be unique within our table.
Entities have a set of properties and strongly-typed entities need to extend from the ITableEntity interface, which expose Partition Key, Row Key, ETag and Timestamp properties. ETag and Timestamp will be generated by Cosmos DB, so we don’t need to set these.
For this tutorial, I’m going to use the above mentioned properties along with two string properties (Email and PhoneNumber) to make up a CustomerEntity type.
#csharp #programming #azure #data #azure cosmos db #azure
1582683309
In this article, we will discuss Azure Cosmos DB. We will answer questions such as: What is a Cosmos DB? Why do we need to use the Cosmos DB? We will also learn how to create a new Azure Cosmos DB account using Azure subscriptions, how to create a new database and collection using Azure, and how to add data to the collection.
In this article, we will see the following,
Prerequisite
Azure Cosmos DB is a globally distributed database service. It supports multi-model approaches such as the document, Key/Value, wide columns and graph databases using APIs.
The list of APIs such as the following:
Azure Cosmos DB is offering the following items:
You can learn in this section, how to create a new Azure cosmos database account using the Azure portal with the following guidelines.
Go to open the new browser, you can copy and paste the following URL
Then, sign in to the Azure portal using Microsoft Account credentials:
After successfully logging into the Azure portal, you can see the dashboard looks like the following screenshot.
You can go to create a resource-Databases - click the Azure Cosmos DB.
The Azure Cosmos DB new account window will be opened and you can enter the following details, which are required. Then, click the Create button.
ID
API
Subscription Name
Resource Group Name
Location
The list of API options is available in the following screenshot:
Now, you can see the notification window displaying the deployment in progress notification. Once it is completed you will get the deployment succeeded notification in the notification window. Then, click the go to resource button.
After successfully creating the Azure Cosmos DB account, the Congratulations! Your Azure Cosmos DB account was created window will be opened, as in the following screenshot.
You will learn in this section, how to create a new database and collection in Data Explorer using Azure portal.
You can go to Data Explorer - click the New Collections
The Add Collection window will be opened and you can enter the following details, which are required. Then, click the OK button.
You can see the new database and collection looks at the following screenshot.
You can learn in this section, how to add sample data to the collection in Data Explorer using Azure portal at the following guidelines.
You can go to Data Explorer - Expand the Table collection in the Collection window, click the Documents - click the New Document.
The new document window will be opened and add the data to the collection with the following format.
{
“Id”: “1”,
“TableName”: “Table A”,
“Location”: “Front Row”,
“Status”: “Available”,
“Date”: “28-02-2018”
}
Once you have added json data to the document, click the Save button.
After successfully added records to the collection it looks like the following screenshot:
You can learn in this section, how to use SQL query to the collection in Data Explorer using Azure portal at the following guidelines.
You can go to Data Explorer - Expand the Table collection in the Collection window, click the New SQL Query
The Query window will be opened as in the below screenshot
Once you have executed query by clicking Execute Query button:
You can use the Where condition and Order By for the select statement on SQL Query window in the Azure Cosmos DB as in the below screenshots:
You will learn in this section, how to get the Cosmos DB connection string in Keys using the Azure portal.
You can go to Settings - click the Keys
Now you can copy the URI and Primary Key into your web.config file in your project
I hope you understand now about Azure Cosmos DB, how to create a new Azure Cosmos DB account using Azure, how to create a new database and collection using Azure, how to add data to the collection using Data Explorer, how to use SQL Query to the collection using Data Explorer and how to get Cosmos DB connection string from Azure. I have covered all the required things. If you find anything missing, please let me know. Thank you!
#Azure #Azure Cosmos DB #Cosmos DB
1623301200
As serverless deployment is becoming popular, equipping yourself with some serverless skills will be paramount. In this article, you will learn how to build a CRUD API using Azure Functions and Azure Cosmos DB 🤩.
From Microsoft’s site, Azure Functions is a serverless compute service (Function as a service) provided by Azure, Microsoft’s cloud service. It lets you run event-triggered code without having to provision or manage any infrastructure explicitly. It contrasts with the classic approach that requires setting up your server, maintaining it, and taking full responsibility for securing it.
Hosting your code on Azure Functions provides you with some cool benefits:
Let’s take a concrete look at how Azure Functions work by building a CRUD API to manage a wishlist.
As a first step, go to the Azure portal.
You need an active Azure subscription to use the cloud services on Azure, including Azure Functions.
It is good practice to wrap all your resources inside a resource group. This makes deleting all used resources inside a resource group easy. So click on Resource groups
icon on your Azure dashboard, as shown below.
Next, click on the Add
button in the Resource groups page to create a resource group and wait for the Create a resource group page to load.
In the Resource group
input field, you can the name for your resource group. In this tutorial, I will use crudtutorial
as the resource group’s name. You can also select any region closer to where you live from the Region
field. I will leave that field as it is and click on the Review + create
button.
After your settings have been reviewed and validated, the Review + create
button will change to Create
. Finally, click on the Create
button to create your resource group.
After the resource group has been created, you will be redirected back to the Resource group page. Click on the crudtutorial
resource group or whatever name you chose for your resource group.
The crudtutorial
resource group page will open. Click on the Add
button to add a resource to the resource group, as shown in the following image:
You will be redirected to a search page for selecting the resource to be created. You can either search for Function App
in the search field (a
) or select Function App
from the list of popular resources (b
).
The Create Function App page opens. Configure the following settings, as depicted by the image below:
swacblooms
in the Function App example I’m building. This is also the name that will be prepended to .azurewebsites.net
to form the Function App domain name (e.g., swacblooms.azurewebsites.net
).Runtime stack
since the function logic will be written in JavaScript.Review + create
button, wait for validation, and then continue by clicking on the Create
button.Wait for the required resources for your Function App are provisioned. When the Go to resource
button becomes active, click on it to navigate to the newly created Function App dashboard.
The overview page will display general information related to your Function App.
Now, you can focus on creating the CRUD API for your wishlist. So, click on the Functions
menu on the left panel.
The CRUD API will be implemented by seven functions:
initialize-list
: For generating a sample wishlist in the database.get-list
: For retrieving all the wishlist items from the database.get-a-list-item
: For retrieving a specific wishlist item from the database.delete-list-items
: For deleting all the wishlist items in the database.delete-a-list-item
: For deleting a wishlist item from the database.create-a-list-item
: For inserting a new wishlist item to the database.update-a-list-item
: For updating a wishlist item in the database.To start, click on the Add
button to create a function. A right panel will slide in containing the required fields needed to configure the function, as you can see in the following image.
On the right panel, you see various available templates to bootstrap your function. Since this tutorial is centered on making a CRUD API triggered through an HTTP request, select HTTP trigger
as the template to use.
Scroll down a little bit on the right panel, and you will see the New Function
field, which allows you to provide the function’s name.
initialize-list
.Authorization level
field, select Anonymous
. This setting will allow you to call the function without attaching an authorization token to the request.Add
button.#crud api #azure #azure functions #azure cosmos db
1624469280
This blog is the final part of a series of blogs where we’ll demystify commonly confused concepts for developers learning how to query data using the SQL (core) API in Azure Cosmos DB. Today, we’ll walk through tips and tricks for querying arrays.
Using an example, we’ll show how to use these concepts when querying arrays:
Example Scenario:
Nick is a developer that created an app that stores shopping lists. His app is incredibly popular around the holidays and has soared to 1 million active users!
He has a Cosmos container that has the shopping lists modeled as JSON documents. Here’s an example document:
{
"id": "Tim",
"city": "Seattle",
"gifts": [
{
"recipient": "Andrew",
"gift": "blanket"
},
{
"recipient": "Deborah",
"gift": "board game"
},
{
"recipient": "Chris",
"gift": "coffee maker"
}
]
}
The remainder of the blog will focus on ways to query arrays, starting with the simplest (and least expressive) and concluding with the more advanced concepts.
#core (sql) api #query #azure cosmos db #azure #cosmos db