MongoDB deep dive
Understanding CRUD, mongoose and building an end to end
authenticated app
Supreme Court example
What is a database
It is a place where data is stored persistently
Express
Browser Database
Express
Express
What is a database
It is a place where data is stored persistently
Express
Servers autoscale
Browser Database
Express
Express
What is a database
It is a place where data is stored persistently
Servers are transient
Browser Database
Express
Express
What is a database
It is a place where data is stored persistently
Database is persistent
Browser Database
Express
Express
What is a database
Examples of data stored in databases -
For Linkedin
1. User data
2. Users posts
3. Users connection relationships
4. Messages
What is a database
Examples of data stored in databases -
Does auth checks
Get me my feed
Express
Give me all posts for this user
Database
Express
What is a database
Good question to have at this point
Why don’t we let the user hit the database directly?
What extra does the http server provide exactly?
Give me all posts for myself
Database
What is a database
Good question to have at this point
Why don’t we let the user hit the database directly?
What extra does the http server provide exactly?
1. Databases were are created using protocols that browsers don’t understand
2. Databases don’t have granual access as a rst class citizen. Very hard to do user speci c access in them
3. There are some databases ( rebase) that let you get rid of the http server and try their best to provide granola access
Give me all posts for myself
Database
fi
fi
fi
What is a database
Databases usually allow access to 4 primitives
1. Create Data
2. Read Data
3. Update Data
4. Delete Data
Popularly known as CRUD
What is a database
Let’s see the API for the mongoose library
Eventually, we’ll be using prisma (which is the industry standard way of doing this)
In mongoose, rst you have to de ne the schema
This sounds counter intuitive since mongodb is schemaless?
That is true, but mongoose makes you de ne schema for things like autocompletions/
Validating data before it goes in the DB to make sure you’re doing things right
Schemaless Dbs can be very dangerous, using schemas in mongo makes it slightly less
Dangerous
fi
fi
fi
What is a database
De ning schema
fi
What is a database
Create
What is a database
Read
What is a database
Update
What is a database
Delete
What is a database
Cluster
3 Jargons to know in Databases Database Database Database
1. Cluster
2. Database Table Table Table Table Table Table
3. Table
Table Table Table Table Table Table
What is a database
What would this mean for a simple course app
Cluster
Database
Users Admins
Courses
What is a database
What would this mean for a simple course app
Cluster
Database
Users
Id | Email | Password | Name | Age User Admins
1 | harkirat@gmail.com | 123123 | harkirat | 20
2 | raman@gmail.com | kirat123 | harkirat | 22
Purchase
Courses
s
What is a database
What would this mean for a simple course app
Cluster
Database
Admins
Id | Email | Password | Name User Admins
1 | admin@gmail.com | 123123 | Raman
2 | admin2@gmail.com | 123123 | Kirat
Purchase
Courses
s
What is a database
Cluster
Database
Courses
id | Title | Description | Price User Admins
1. | Full stack | Learn Full stack | 5000
2. | Web3 | Learn Web3. | 3999
Purchase
Courses
s
What is a database
What would this mean for a simple course app
Cluster
Database
Purchases
user_id | course_id | timestamp | payment_ref User Admins
1. |1 | 02/12/2024. | pay_123123
2. |1 | 02/12/2024. | pay_331213
Purchase
Courses
s
What is a database
Lets try to target the assignments from this week
What is a database
Something extra
You can attach methods to schema
And call them on objects later