Mongodb Guide

What is MongoDB

1. Definition

MongoDB is a NoSQL database that stores data in a flexible, JSON-like format called documents instead of traditional tables. It is commonly used in modern web applications for handling large and dynamic data.

2. When to Use MongoDB

  • When data structure is not fixed
  • Building scalable applications
  • Handling large volumes of data
  • MERN stack development

3. Where it is Used

  • Web applications
  • Real-time analytics
  • Content management systems
  • E-commerce platforms
  • Big data applications

4. Why We Use MongoDB

  • Flexible schema (no strict structure)
  • Easy to scale horizontally
  • High performance
  • Stores JSON-like data (developer friendly)

5. How MongoDB Works

  • Stores data as documents (JSON/BSON format)
  • Documents are grouped into collections
  • Collections are stored inside databases
  • Supports indexing and querying for fast access

Basic Syntax

db.users.insertOne({
  name: "Manaswini",
  age: 22,
  role: "Developer"
});

Real Example

db.orders.insertOne({
  product: "Laptop",
  price: 50000,
  user: {
    name: "Manaswini",
    location: "India"
  }
});

6. Explanation

  • Data is stored as a document
  • No fixed schema required
  • Nested objects are allowed
  • Easy to represent real-world data

7. Advantages

  • Flexible and schema-less
  • Highly scalable
  • Fast read and write operations
  • Great for modern applications

8. Disadvantages

  • No strong relationships like SQL joins
  • Data duplication may occur
  • Less strict data validation

Interview Points

  • MongoDB is a NoSQL database
  • Stores data in document format (JSON/BSON)
  • Uses collections instead of tables
  • Schema-less and scalable