cosmos-db
  1. cosmos-db-table

CosmosDB Data Models

Syntax

CosmosDB supports multiple data models including:

  • Document data model
  • Key-value data model
  • Graph data model
  • Column-family data model

Example

{
  "id": "1",
  "title": "CosmosDB data models",
  "content": "This is an example of document data model in CosmosDB"
}

Output

CosmosDB stores the document in JSON format with a unique identifier id.

Explanation

A table in CosmosDB can have documents with different data models.

  • The document data model stores data as key-value pairs within a JSON document.
  • The key-value data model stores a collection of items with each item having a unique key and a value.
  • The graph data model stores data as nodes and edges, and is useful for representing complex relationships.
  • The column-family data model stores data as column families, with each family containing a set of columns.

Use

Choose the appropriate data model based on the type of data and the queries you will be performing.

For example, if you have data with complex relationships, use the graph data model. If you have data with a fixed schema, use the column-family data model.

Important Points

  • CosmosDB supports multiple data models for storing data.
  • Choose the right data model for your data and query patterns.
  • JSON data is used in the document, key-value and graph data models.

Summary

In CosmosDB, you can choose from different data models to store your data. Each data model has its own strengths and weaknesses, so choose the one that best suits your needs.

Published on: