Skip to content

Latest commit

 

History

History

01-Oh-CRUD

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
title logoImg theme transition highlightTheme slideNumber enableMenu enableChalkboard
Introduction to Mongo
night
slide
dracula
true
false
false

Why learn MongoDB?

:::block

{.column} :::

:::block JavaScript-like Syntax

  • Simple to learn

{.double-column .fragment} :::


What is JSON?

  • Stands for, JavaScript Object Notation
  • Curly braces, {} hold objects
  • Square brackets, [] hold arrays
  • Data is in name/value pairs
  • keys must be strings, written with double quotes:
    { "name":"John" }
  • Data is separated by commas
    { "name":"John" },
    { "name":"Jane" }

BSON is Binary JSON

Has more datatypes than javascript {.fragment .current-only data-code-focus=1-1 }

Table of Mongo DataTypes


What is C.R.U.D.?

:::block

{style=width:50%;float:left; height:50%}

:::

:::block Create with insert( ) { .fragment }

Read with find( ) { .fragment }

Update with update( ) { .fragment }

Delete with remove( ) { .fragment }

{style=width:50%;float:right; height:50%} :::


Comparing CREATE Methods

Query Syntax: SQL

:::block

INSERT INTO book('title', 'author')
VALUES('JavaScript First', '@HansOnConsult');

{.column} :::

:::block Step:1 INSERT INTO speficies the table book will be added {.fragment .current-only data-code-focus=1-1}

The ( ) set the something {.fragment .current-only data-code-focus=1-1}

VALUES() stores the information in columns {.fragment .current-only data-code-focus=2-2}

{.double-column} :::


Comparing CREATE Methods

Query Syntax: Mongo

:::block

db.book.insert(
  {
    title:"JavaScript First",
    author:"HansOnConsult"
  }
);

{.column} :::

:::block

db refers to the current database {.fragment .current-only data-code-focus=1-1}

book refers to the collection {.fragment .current-only data-code-focus=1-1}

Start {} {.fragment .current-only data-code-focus=2-2}

Ends {} {.fragment .current-only data-code-focus=5-5}

title refers to the key {.fragment .current-only data-code-focus=3-3 }

the text inside " " refers to the value {.fragment .current-only data-code-focus=3-4 }

{.double-column} :::


Exercise 1: Oh CRUD...

To get started just click the gitpod button after signing into github, then type mongo into the shell..

--

Oh CRUD... Methods

:::block

use stateBar

db
.stateBar
.insert(
  {
    name: 'Hans', row:1, os:'Mac', 
    hobbies:['Hardware Design', '3D Prototyping'] 
  }
)
db.stateBar
.find({row:1})

db.stateBar
.update({name: "Hans"}, 
{$push: {"hobbies":"Teaching"}})

db.stateBar.insert({name: 'Doug', row:2, os:'linux', hobbies:['Crime'] })

db.stateBar.remove({name:"Doug"})

{style=width:80%;float:left} :::

:::block

Select the mongo database {.fragment .current-only data-code-focus=1-1}

calls the selected database {.fragment .current-only data-code-focus=3-3}

calls the selected collection {.fragment .current-only data-code-focus=4-4}

CREATES the data by inserting the {} into our collection {.fragment .current-only data-code-focus=5-10}

call the database and the collection {.fragment .current-only data-code-focus=11-11}

READS the data in our collection and find the everyone in row 1 {.fragment .current-only data-code-focus=12-12}

UPDATES the data by pushing a new hobby, to "Hans" {.fragment .current-only data-code-focus=15-16}

add another lawyer from the state bar, "Doug" {.fragment .current-only data-code-focus=18-18}

DELETE the lawyer "Doug" {.fragment .current-only data-code-focus=20-20}

{style=width:20%;float:right}

:::