Skip to content

Latest commit

 

History

History
57 lines (41 loc) · 1.45 KB

cosmosDBTasks.md

File metadata and controls

57 lines (41 loc) · 1.45 KB

Creation of ComosDB and uploading items:

Step 1: Go to portal.azure.com, click on create new resource and search Azure Cosmos DB. From there click on create and select “Core (SQL) - Recommended” After completion of the above process, we can perform the following tasks.

Step 2: We can start uploading the JSON data through the upload item option with Partition key as product id

image

Step 3: Also, created the Stored Procedure named “insertingData” in JavaScript to upload items through it.

Stored Procedure script:

 function createDocument(doc) {
     var context = getContext();
     var collection = context.getCollection();
     var accepted = collection.createDocument(
         collection.getSelfLink(),
         doc,
         function (err, newDoc) {
             if (err) throw new Error('Error' + err.message);
             context.getResponse().setBody(newDoc);
         }
     );
     if (!accepted) return;
 }

Click on execute and provide input params:

image

image

image

Step 4: Creation of UDF for calculation of tax

UDF script

function getTax(price) {
        if(price == undefined)
            throw 'no input';
        if (price < 100)
            return price * 0.1;
        else
            return price * 0.2;
}

image

Execution of UDF:

image