DEV Community

Cover image for MongoDB
Kausi Tarun
Kausi Tarun

Posted on

MongoDB

Introduction to MongoDB

MongoDB is a NoSQL (Non-Relational) database that stores data in a flexible, document-oriented format called BSON (Binary JSON). It is widely used for modern applications that require scalability, flexibility, and high performance.

🧩 Key Features of MongoDB

  1. Document-Oriented Storage

Data is stored in documents (similar to JSON objects).

Each document contains key–value pairs, making it more flexible than traditional row-column structures.

  1. Schema-less

Unlike SQL databases, MongoDB does not require a fixed schema.

Documents in the same collection can have different fields and structures.

  1. Collections and Databases

A database contains multiple collections.

A collection contains multiple documents.
(Equivalent of table → collection, and row → document in SQL.)

  1. Scalability

Supports horizontal scaling using sharding, allowing data to be distributed across multiple servers.

  1. Replication and High Availability

MongoDB uses replica sets for automatic failover and data redundancy.

  1. Rich Query Language

Supports powerful queries, filtering, aggregation, and indexing for performance optimization.

⚙️ Basic MongoDB Structure

SQL Term MongoDB Equivalent

Database Database
Table Collection
Row Document
Column Field
Primary Key _id field (auto-generated)

🚀 Advantages of MongoDB

Flexible data model

High performance and scalability

Easy integration with programming languages (like Python, Java, Node.js, etc.)

Ideal for big data, real-time analytics, and cloud applications

Schema (Collection: students)
Each student document should follow the structure below:
{
"student_id": "S001",
"name": "Santhosh",
"age": 20,
"department": "CSBS",
"year": 2,
"cgpa": 9
}

1️⃣ Create (Insert)
Insert at least 5 student records into the students collection.

2️⃣ Read (Query)
Display all student records.

Find all students with CGPA > 8.

Find students belonging to the Computer Science department.

3️⃣ Update
Update the CGPA of a specific student.

Increase the year of study for all 3rd year students by 1.

4️⃣ Delete
Delete one student record by student_id.

Delete all students having CGPA < 7.5.
Deliverables
MongoDB queries (insert, find, update, delete.

Conclusion

MongoDB is a powerful database solution designed for handling large volumes of unstructured or semi-structured data efficiently. Its flexibility, scalability, and ease of use make it a popular choice for modern web and mobile applications.

Top comments (0)