Create an Azure Cosmos DB for NoSQL account
Before diving too deeply into Azure Cosmos DB, it’s important to get a handle on the basics of creating the resources you will use the most. In most scenarios, you will need to be comfortable creating accounts, databases, containers, and items. In a real-world scenario, you should also have a few basic queries “on hand” to test that you created all of your resources correctly.
In this lab, you’ll create a new Azure Cosmos DB account using the for NoSQL. You will then use the Data Explorer to create a database, a container, and two items. Finally, you will query the database for the items you created.
Create a new Azure Cosmos DB account
Azure Cosmos DB is a cloud-based NoSQL database service that supports multiple APIs. When provisioning an Azure Cosmos DB account for the first time, you will select which of the APIs you want the account to support (for example, Mongo API or NoSQL API).
-
In a new web browser window or tab, navigate to the Azure portal (
portal.azure.com
). -
Sign into the portal using the Microsoft credentials associated with your subscription.
-
Within the Azure services category, select Create a resource, and then select Azure Cosmos DB.
💡 Alternatively; expand the ≡ menu, select All Services, in the Databases category, select Azure Cosmos DB, and then select Create.
-
In the Select API option pane, select the Create option within the Azure Cosmos DB for NoSQL section.
-
Within the Create Azure Cosmos DB Account pane, observe the Basics tab.
-
On the Basics tab, enter the following values for each setting:
Setting Value Subscription Use your existing Azure subscription. All resources must belong to a resource group. Every resource group must belong to a subscription. Resource Group Use existing or create a new resource group. All resources must belong to a resource group. Account Name Enter any globally unique name. The globally unique account name. This name will be used as part of the DNS address for requests. The portal will check the name in real time. Location Choose any available region. Select the geographical region from which your database will initially be hosted. Capacity mode Provisioned throughput Apply Free Tier Discount Do Not Apply -
Select Review + Create to navigate to the Review + Create tab, and then select Create.
📝 It can take 10-15 minutes for the Azure Cosmos DB for NoSQL account to be ready for use.
-
Observe the Deployment pane. When the deployment is complete, the pane will update with a Deployment successful message.
-
Still within the Deployment pane, select Go to resource.
Use the Data Explorer to create a new database and container
The Data Explorer will be your primary tool to manage the Azure Cosmos DB for NoSQL database and containers in the Azure portal. You will create a basic database and container to use in this lab.
-
From within the Azure Cosmos DB account pane, select Data Explorer from the resource menu.
-
In the Data Explorer pane, select New Container.
-
In the New Container popup, enter the following values for each setting, and then select OK:
Setting Value Database id cosmicworks Share throughput across containers Unckecked Container id products Partition key /categoryId Container throughput (autoscale) Manual RU/s 400 -
Back in the Data Explorer pane, expand the cosmicworks database node and then observe the products container node within the hierarchy.
Use the Data Explorer to create new items
The Data Explorer also includes a suite of features to query, create, and manage items in an Azure Cosmos DB for NoSQL container. You will create two basic items using raw JSON in the Data Explorer.
-
In the Data Explorer pane, expand the cosmicworks database node, expand the products container node, and then select Items.
-
Select New Item from the command bar, and in the editor, replace the placeholder JSON item with the following content:
{ "categoryId": "4F34E180-384D-42FC-AC10-FEC30227577F", "categoryName": "Components, Pedals", "sku": "PD-R563", "name": "ML Road Pedal", "price": 62.09 }
-
Select Save from the command bar to add the first JSON item:
-
Back in the Items tab, select New Item from the command bar. In the editor, replace the placeholder JSON item with the following content:
{ "categoryId": "75BF1ACB-168D-469C-9AA3-1FD26BB4EA4C", "categoryName": "Bikes, Touring Bikes", "sku": "BK-T18Y-44", "name": "Touring-3000 Yellow, 44", "price": 742.35 }
-
Select Save from the command bar to add the second JSON item:
-
In the Items tab, observe the two new items in the Items pane.
Use the Data Explorer to issue a basic query
Finally, the Data Explorer has a built-in query editor that is used to issue queries, observe the results, and measure impact in terms of request units per second (RU/s).
-
In the Data Explorer pane, select New SQL Query.
-
In the query tab, select Execute Query to view a standard query that selects all items without any filters.
-
Delete the contents of the editor area.
-
Replace the placeholder query with the following content:
SELECT * FROM products p WHERE p.price > 500
📝 This query will select all items where the price is greater than $500.
-
Select Execute Query.
-
Observe the results of the query, which should include a single JSON item and all of its properties.
-
In the Query tab, select Query Stats.
-
Still in the Query tab, observe the value of the Request Charge field within the Query Statistics section.
📝 Typically, the request charge for this simple query is between 2 and 3 RU/s when the container size is small.
-
Close your web browser window or tab.