NoSQL & MongoDB | Lecture 13
NoSQL & MongoDB
1. What is a Database?
A database is a place where we store data permanently.
Example:
Student details
User login info
Products in an e-commerce site
2. What is NoSQL?
NoSQL means Not Only SQL.
It stores data without tables, rows, and columns.
Why NoSQL?
Handles large data
Very fast
Easy to scale
Works well with modern web apps
3. SQL vs NoSQL (Simple Table)
| SQL | NoSQL |
|---|---|
| Tables | Collections |
| Rows | Documents |
| Fixed schema | Flexible schema |
| MySQL | MongoDB |
4. Types of NoSQL Databases
Document-based → MongoDB
Key-Value → Redis
Column-based → Cassandra
Graph → Neo4j
We focus on MongoDB
5. What is MongoDB?
MongoDB is a NoSQL document-based database.
It stores data in JSON-like format called BSON.
6. MongoDB Basic Terms
| Term | Meaning |
|---|---|
| Database | Main container |
| Collection | Like a table |
| Document | Like a row |
| Field | Like a column |
7. Example of MongoDB Document
{
"name": "Aakash",
"age": 25,
"course": "MERN Stack"
}
One document
Stored inside a collection
8. MongoDB Structure
Database
└── Collection
└── Document
9. Install MongoDB (Basic Idea)
Install MongoDB Community Server
Use MongoDB Compass (GUI)
Or use MongoDB Atlas (Cloud)
10. Create Database & Collection
use schoolDB
Create collection automatically:
db.students.insertOne({ name: "Rahul", age: 20 })
11. Insert Data
Insert One
db.students.insertOne({
name: "Neha",
age: 22
});
Insert Many
db.students.insertMany([
{ name: "Amit", age: 21 },
{ name: "Riya", age: 23 }
]);
12. Read Data (Find)
Find All
db.students.find()
Find with Condition
db.students.find({ age: 22 })
13. Update Data
Update One
db.students.updateOne(
{ name: "Neha" },
{ $set: { age: 23 } }
);
14. Delete Data
Delete One
db.students.deleteOne({ name: "Amit" });
Comments
Post a Comment