Databases
Announcements
Attendance (Google Forms)
Secret word: ‘’Haas”
Databases Intro
Databases
How is data structured?
SQL: organized spreadsheet
NoSQL: flexible folders w/notes
SQL = Structured, safe, consistent, great for complex relationships and queries. Examples: E-Commerce, Banking, Airline Systems
NoSQL = Fast, flexible, perfect for apps that change often or grow quickly. Examples: Social Media, Chat Apps, Streaming Platforms
Overall
Supabase (Relational DB Example)
The dotted lines show relationships between tables
For example:
messages.channel_id → channels.id
messages.user_id → users.id
Each box is a table (rows + columns)
Firebase (Non-relational DB Example)
looks more like JSON, not a table with rows and cols
SQL & Relational Databases
What is SQL?
SQL is Declarative
What is a schema?
What is a relational database?
A relational database is a type of database that stores data in tables, kind of like Excel spreadsheets.
Each table is made up of:
Each row is related to a single user. We can connect this to other tables using a common field like ID → thus RELATIONAL database, relational table
SQL vs NoSQL = Relational vs non-relational databases?
NoSQL & Non-relational Databases
What is NoSQL?
What is a non-relational database?
MongoDB
What is MongoDB
How does MongoDB work?
You need
MongoDB Atlas - create cluster
Make sure to select these! (free!!)
PASSWORD: DO NOT USE
SPECIAL SYMBOLS JUST USE
NUMBERS AND LETTERS
Stop here for now…
You’ll need it later
How to download MongoDB
How to start MongoDB
Some MongoDB commands
Start MongoDB:
In mongosh:
MongoDB on VS Code
You can alternatively download mongodb on VS Code in extensions!
MongoDB & Express
Full Stack Breakdown
Why Start a Server for MongoDB?
Mongo Servers in Express
Plan:
Terminal
You can also do this by creating a new cluster in Atlas
server.js
Access the endpoint
Graph Databases & Neo4j
What is a graph database?
A graph database is a database designed to store things and the connections between them.
It uses:
A graph database like Neo4j is usually classified as non-relational / NoSQL because it does not use the relational table model even though it illustrates relationships.
When should you use it?
Use a graph database when relationships between data are the core focus.
Best for:
Choose it over SQL when you need to traverse connections.
Use SQL instead when your app is mostly structured records like users, orders, and payments.
Neo4j (a Graph DB)
Cypher
Cypher is Neo4j’s query language
CREATE
(a:Course {code: 'CS61A', name: 'SICP'}),
(b:Course {code: 'CS61B', name: 'Data Structures'}),
(c:Course {code: 'CS70', name: 'Discrete Math'}),
(d:Course {code: 'CS162', name: 'Operating Systems'}),
(b)-[:PREREQ]->(a),
(c)-[:PREREQ]->(b),
(d)-[:PREREQ]->(c);
Commands
cd ~/Downloads
mkdir neo4j-demo
cd neo4j-demo
npm init -y
npm install express neo4j-driver dotenv
mkdir public
touch server.js .env public/index.html
node server.js
server.js
.env
NEO4J_URI=neo4j+s://your-database-id.databases.neo4j.io
NEO4J_USERNAME=neo4j
NEO4J_PASSWORD=your_password_here
public/index.html
Attendance (Google Forms)
Secret word: ‘’Haas”