Azure Cosmos DB 101 (Logic App)

Logic APP notes

Connect to Azure Cosmos DB – Azure Logic Apps | Microsoft Learn

  • Currently, only stateful workflows in a Logic App (Standard) resource can use both the managed connector operations and built-in operations. Stateless workflows can use only built-in operations.
  • The Azure Cosmos DB connector supports only Azure Cosmos DB accounts created with Azure Cosmos DB for NoSQL.

Tutorial Cosmos DB

Quickstart – Create Azure Cosmos DB resources from the Azure portal | Microsoft Learn

Capacity mode Server less for testing, otherwise can get needed RU, i.e 5000.

Networking

Review the account settings, and then select Create. It takes a few minutes to create the account. Wait for the portal page to display Your deployment is complete.

Add a database and a container

You can use the Data Explorer in the Azure portal to create a database and container.

Select Data Explorer from the left navigation on your Azure Cosmos DB account page, and then select New Container > New Container.

You may need to scroll right to see the New Container window.

Cosmos DB data is stored in containers

DB ToDoList

Container items

Partition key /category

Select OK. The Data Explorer displays the new database and the container that you created.

Add data to your database
Add data to your new database using Data Explorer.

In Data Explorer, expand the ToDoList database, and expand the Items container.

Next, select Items, and then select New Item.

Add the following to the first item and save it (meta data will appear automatically)

{
    "id": "1",
    "category": "personal",
    "name": "food",
    "description": "Pick up tomato and milk.",
    "isComplete": false
}

Select New Item again, and create and save another document with a unique id, and any other properties and values you want. Your documents can have any structure, because Azure Cosmos DB doesn’t impose any schema on your data.

Query your data

You can use queries in Data Explorer to retrieve and filter your data.

At the top of the Items tab in Data Explorer, review the default query SELECT * FROM c. This query retrieves and displays all documents from the container ordered by ID.

To change the query, select Edit Filter, replace the default query with ORDER BY c._ts DESC, and then select Apply Filter.

Delete it and create Historian

If you’re familiar with SQL syntax, you can enter any supported SQL queries in the query predicate box. You can also use Data Explorer to create stored procedures, user defined functions, and triggers for server-side business logic.

NoSQL queries – Azure Cosmos DB for NoSQL | Microsoft Learn

Data Explorer provides easy access in the Azure portal to all of the built-in programmatic data access features available in the APIs. You can also use the Azure portal to scale throughput, get keys and connection strings, and review metrics and SLAs for your Azure Cosmos DB account.

Historian

Database id Historian, container tags, Partition key /type, could also add hierarchical partition key with system

TAG-12 type=analog, system=12

TAG-13 type=analog, system=13

So we could create two containers one storing the data

{
    "id": "1",
    "type": "analog",
    "name": "TAG-12",
    "quality": "GOOD",
    "value" : 78.25,
    "ts": "2023-07-30T-20:00:00.245Z"
}

And one storing all metadata or store all in the same but edit the id on the metadata and use the name column for getting all values and the metadata in a join.

{
    "id": "1",
    "type": "analog",
    "name": "TAG-12",
    "description": "Pressure on deck 12",
    "project": "2013-08-17 789 New replacement",
    "supplier": "Duck Inc.",
    "customer": "Mouse Inc",
    "metadata". "Even more data"
}

So we have 5 items now with 5 values, ts and quality

Insert one bad also

Count where value > 90

There is Integration

Power BI has already selected the database and container

And Explorers

Browse is just that, and add collection (db and container), the rest is more of the same or retired-> USE Data Explorer