NoSQL Databases

by K. Yue

1. Introduction

2. Advantages and Disadvantages

3. ACID versus BASE Transaction Models

3.1 ACID

3.2 BASE

3.3 CAP Theorem

4. Major NoSQL data models

4.1 Key-value model

  1. Data is stored as key-value pairs.
  2. Values can possibly be JavaScript Object Notation (JSON) strings, which store serialized objects.
  3. Some key-value databases support rich JSON queries.

4.2 Document Model

  1. Document-oriented databases store data as documents.
  2. Documents can be considered as semi-structured data.
  3. Thus, XML databases can be considered as employing the document model.
  4. Modern document-oriented databases commonly employ JSON. E.g., MongoDB and CouchDB.
  5. The document model can be considered as a subclass of key-value model.
    1. The stored value of a key-value model can be a document.
    2. The stored value can be manipulated by operations based on the selected document model (mostly JSON).
  6. MongoDB is likely the most popular document-oriented NoSQL DB. It will be covered in more details in this class.

Example: In CouchDB, a key-value pair may be:

Key: "MBSEBaseModel~939c7672-5d2d-11ec-bf63-0242ac130002"

Value to be stored:

{
   "BCAssetId": "939c7672-5d2d-11ec-bf63-0242ac130002",
   "BCAssetType": "MBSEBaseModel",
   "BCAssetName": "Gateway-PPE-Base-Model",
   "BaseModelDesc": "PPE project's model.",
   "version": {
      "version": "2.1",
      "subversion": "4.6",
      "startTime": "2021-12-08T17:25:23+06:00"
   },
   "storage": {
      "isEncrypted": true,
      "EncrypMethod": "AES256",
      "EncrypKey": "q4t7w!z%C*F-JaNdRgUkXp2r5u8x/A?D",
      "useIPFS": true,
      "IPFSCid": "QmT5NvUtoM5nWFfrQdVrFtvGfKFmG7AHE8P34isapyhCxX",
      "IPFS_HashHead": "A0Xa",
      "payloadRaw": "raw PPE MBSE Base model description. V2.1.4.6.",
   }
}

Note:

To query CouchDB, one may use many methods. Examples:

  1. CouchDB RESTful API: https://docs.couchdb.org/en/latest/api/index.html
  2. MapReduce-based views: https://docs.couchdb.org/en/latest/ddocs/views/index.html
  3. Mango query

An example Mango query that returns all CouchDB key-value pairs for MBSEBaseModel.

{
    "selector": {
        "BCAssetType": { "$eq": "MBSEBaseModel" }
    }
}

See https://docs.couchdb.org/en/latest/api/database/find.html for more information about selector syntax.

4.3 Wide-Column Model

  1. A columnar DBMS or column-oriented DBMS stores data tables grouped by columns, instead of grouped by rows (as in most relational DBMS).
    1. For example, related columns may be stored together in a file for faster performance.
    2. Benefits:
      1. Faster access for certain types of queries.
      2. Better chance for data compression.
    3. Disadvantages:
      1. Slower update.
      2. Slower access for certain types of queries.
  2. Read introductions to the wide-column model. Examples:
    1. https://dandkim.com/wide-column-databases/
  3. In wide column model, data is stored as keys and columns. Each column contains a column-name and a value.
  4. Thus, to get a data value, use (key, column-name).
  5. Cassandra is one of the most popular wide-column databases.

4.4 Graphical Model

  1. "A graph database stores nodes and relationships instead of tables, or documents."
  2. Quite object-oriented, using a directed graph model.
  3. neo4j is the most popular graphical database.
  4. Introduction: https://neo4j.com/developer/graph-database/.
  5. To start learning Neo4j, download and install Neo4j desktop.
  6. Neo4j Query Language: Cypher, https://neo4j.com/developer/cypher/.
  7. Basic Cypher syntax: (nodes)-[:ARE_CONNECTED_TO]->(otherNodes).