Cosmos DB for Entities

ES | EN

Available from version 2.0.0-fireball

From version 3.1.0 in the Control Panel, Ontologies have been renamed as Entities. This does not alter any functionality, simply the nomenclature has been changed for a better understanding of the concept.

Azure Cosmos DB

Cosmos DB is a distributed, horizontally scaled, multi-model database service offered as a service on Azure.

It enables global distribution of data over a given number of Azure regions, with a transparent process of data scaling and replication.

It is multi-model and natively supports document data models, key-value pairs, graphs, and columns. It also allows access to your data with different APIs: such as SQL (documents), MongoDB (documents), Azure Table Storage (key-value), Gremlin (graphs) and Cassandra (in columns).

Azure Cosmos DB account requirements

In order to integrate the CosmosDB repository into the Onesait Platform, we need to create a CosmosDB account that must meet the following requirements:

  1. It must be of the SQL API type

  2. You must create a new database: onesaitplatform_rtdb

Configuration of Cosmos DB inside Configuración de la cuenta en onesait Platform

To configure the Cosmos DB account in the platform, head to the configuration management in controlpanel and update the global configuration. Add the following properties:

  • comosdb-master-key: azure cosmos DB master key

  • comosdb-host: connection URL of Cosmos DB

Creation of an ontology over Cosmos DB

To create an ontology with this type of repository, go to the ontology creation wizard, filling all required fields.

Then, click on Advanced Settings, and choose CosmosDB in the RTDB Instance combo.

Two new input fields will appear: Partition Key and Unique Keys.

 

Partition Key is the partition key that Cosmos DB will use to create containers according to input data. This partition key will be an ontology attribute path. PK is /id by default, but it’s highly recommended to change it, since partitioning by unique id is underperformance.

Unique Keys (separated by ',' if multiple) are the ontology attribute paths that will be unique throughout the collection, something similar to the UNIQUE CONSTRAINTS relational DDBB.

For this example, we are using a copy of the Restaurant ontology, and we will choose the following keys:

The ontology data will be partitioned by borough, and the restaurant_id will be unique.

Once created, you can start developing as with any other kind of ontology, but with some peculiarities in the queries.

Queries over Cosmos DB ontologies

First of all, you need to be aware that the JOIN feature between collections/ontologies (cross-documents) is not natively supported by Cosmos DB, so you’ll need to design the data model carefully.

https://docs.microsoft.com/en-us/azure/cosmos-db/modeling-data

Only intra-document JOINs are supported, as stated in this guides:

https://docs.microsoft.com/es-es/azure/cosmos-db/sql-query-working-with-json

UPDATE and DELETE

As a peculiarity of the nature of this repository, UPDATE and DELETE sentences will need to carry a projection, as shown here:

SQL Functions

The following SQL functions are available when making queries:

  • UNSET: removes an attribute of the ontology

  • APPEND: adds and object or raw value, to an existing array attribute

  • BOOLEAN: takes true or false as an argument, and transforms it to an actual boolean value

 

  • OBJECT: takes a stringified object as argument, and transforms it to an object.

Â