NoSQL API Documents

Learn the advantages and disadvantages of a document database, how to overcome some limitations, and the specific structure in Cosmos DB.

The elephant in the room

Cosmos DB doesn’t use conventional tables to store the data. For the database, everything is a JSON document!

A document representing a game for our store might look like the following:

Press + to interact
{
"title": "Mario",
"year": 1983
"category": "Platform",
"price": 20
}

But why would anyone prefer JSON over a predefined column-based structure?

No rules

The first thing that comes to mind when thinking about documents is flexibility. Usually, in relational databases, we first need to define a set of columns for our table.

Each column usually has the following:

  • Name

  • Type (string, integer, boolean)

  • A column value if it’s required, otherwise, it can be left empty

  • Sometimes a default value, if no column value is present

Every time we want to change the columns, we need to alter the table, and the change affects all existing rows. Sometimes, based on constraints, the database blocks the operation altogether. With JSON documents, we ...