Working with Stored Procedure in Azure DocumentDB (CosmosDB)
In this blog post we will learn how to create & test Stored Procedure in Azure DocumentDB (CosmosDB).
Login to Azure Portal & click on New. Search for cosmosDB-
Click on "Azure Cosmos DB".
Login to Azure Portal & click on New. Search for cosmosDB-
Click on "Azure Cosmos DB".
Click on "Create".
Fill up all details e.g.- CosmosDB ID, API (for this demonstration we will select DocumentDB), Subscription, Resource Group & Location. Click on "Create" button.
After creating cosmos DB ID you can view as below screenshot-
Below are the some important points which we should keep in mind-
1. We can create multiple Databases under one Cosmos DB.
2. One database can have multiple collections.
3. One collection can have multiple documents.
4. Each document have one field as "id" this is primary key for each document. This is also unique under one collection. We can't create multiple documents with same id under one collection.
To create collection and database click on "Add Collection" button.
If you keep storage capacity as "unlimited" than Partition Key is mandatory. You can select fixed option under storage capacity & keep partitionkey blank.
Lets create some document under collection for testing. Select "Document Explorer" option from Cosmos DB panel.
Click on "Create" option in top option bar.
Add value of id field & add other fields for your document. For now we will add below fields-
Click on "Save" option.
For Creating & Testing Stored Procedure, Azure provides "Script Explorer". In the Cosmos DB panel click on "Script Explorer"-
Select your Database and Collection name & click on "Create Stored Procedure".
Provide "ID" for Stored Procedure. With new Stored Procedure some basic template is provided to check document in collection. You can customize it as per your requirement.
For testing Stored Procedure, scroll to downside of screen to view place to give input parameters for Stored Procedure & view execution result.
If there are no record found in collection than you will get below result.
If you have added documents in collection (as we did in earlier steps), you will get below result-
Result will be look like as below-
test{"id":"1","firstName":"Dharam","lastName":"Sikhwal","Company":"Spadeworx","City":"Pune","_rid":"EyMIAKblHwUBAAAAAAAAAA==","_self":"dbs/EyMIAA==/colls/EyMIAKblHwU=/docs/EyMIAKblHwUBAAAAAAAAAA==/","_etag":"\"0000ce00-0000-0000-0000-5961c3b10000\"","_attachments":"attachments/","_ts":1499579312}
I hope you have understood basic concept of Azure DocumentDB, Documents and Stored Procedure. In next blog we will walk you through using DocumentDB Stored Procedure in Azure Logic Apps.
If you have any query please send email on dharam.pal95@gmail.com.
This was truly awesome. thanks so much for this..!!..Keep Share your informationAzure Online Training Bangalore
ReplyDelete