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)

SQLNoSQL
TablesCollections
RowsDocuments
Fixed schemaFlexible schema
MySQLMongoDB

4. Types of NoSQL Databases

  1. Document-based → MongoDB 

  2. Key-Value → Redis

  3. Column-based → Cassandra

  4. 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

TermMeaning
DatabaseMain container
CollectionLike a table
DocumentLike a row
FieldLike 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

Popular posts from this blog

Introduction to Node.js | Lecture 1

Introduction to NPM | Lecture 2

Modules in Node.js | Lecture 4