Data Modeling & NoSQL Database - andrewkyllo-401-advanced-javascript/seattle-javascript-401d34 GitHub Wiki

Javascript Data Modeling

  • The process of taking a real world or conceptual idea and encoding it into Javascript's built in data types.

Modeling Behaviors

CRUD - Basic data operations

  • CREATE Add a record to a data store
  • READ Retrieve a record from a data store
  • UPDATE Update a record within a data store
  • DELETE Remove a record from a data store

Interfaces & Services - The "Repository" design pattern

  • A layer of abstraction that sits between the code and the actual data source.

Implementation

  • The code in the methods that do the actual work.

Normalization and Validation

  • Sanity checking data to ensure that it conforms to the modeling rules, integrity checks, etc.

NoSQL Databases

SQL

  • Store data in rows and columns and link related records through a system of keys and pointers(Foreign Keys).

NoSQL

  • Based on document storage
  • Stores data as records that is easily and quickly accessible.
  • Stored as pure JSON object.
  • Great for "Read-Heavy" usage and frequent aggregations

NoSQL Data Modeling

  • Start with considering the data you NEED, not data thats available.

ORMs (Mongoose)

  • Enter "Mongoose" and "ORM" for the Mongo database.

ORM - Object Relation Mapping

  • Rules for Document databases.
  • Mongoose is a Node library that helps developers interface with Mongo database and reliably structure data.
  • Mongo provides a Schema and CRUD methods Mongoose "Scehma"
const players = mongoose.Schema({
  name: { type: String, required: true },
  position: { type: String, required: true, uppercase: true, enum: ['P', 'C', '1B', '2B', '3B', 'SS', 'LF', 'RF', 'CF'] },
  throws: { type: String, required: true, uppercase: true, enum: ['R', 'L'] },
  bats: { type: String, required: true, uppercase: true, enum: ['R', 'L'] },
  team: { type: String, required: true },
});

Mongoose Built-in CRUD Methods

 let newRecord = new schema(record);
    return newRecord.save();

    schema.findOneByIdAndDelete(id);

    schema(findById(id));

Mongo DB Clinents

Running a local mongodb server

mongod --dbpath=[/PATH/TO/DATA/FOLDER]

  • Starts a mong db server. Replace path with actual path on computer to database

Accessing Mongo Data

  • Command line client mongo