MongoDB - NOSQL Database

MongoDB is a document-oriented NoSQL database used for high-volume data storage. Instead of using tables and rows as in relational databases, MongoDB uses collections and documents.

Key Features of MongoDB

  1. Schema-less – No fixed structure, allowing flexibility.

  2. Scalability – Horizontally scalable using sharding.

  3. High Performance – Fast read and write operations.

  4. Replication – Provides high availability using replica sets.

  5. Indexing – Supports different types of indexes to improve query performance.

  6. Aggregation Framework – Enables complex data transformations.

MongoDB Architecture

MongoDB follows a distributed architecture with multiple components:

  1. Client – Applications interact with MongoDB using drivers.

  2. MongoDB Server – Stores and manages the data.

  3. Replica Set – Ensures fault tolerance and high availability.

  4. Sharded Cluster – Enables horizontal scaling for large datasets.

  5. Config Servers – Store metadata for sharded clusters.

  6. Mongos Router – Distributes queries across shards.

Basic MongoDB Operations

1. Creating a Database

use myDatabase;
  1. Creating a Collection

db.createCollection("users");
  1. Inserting a Document

db.users.insertOne({
    name: "John Doe",
    email: "[email protected]",
    age: 28,
    created_at: new Date()
});
  1. Finding Documents

db.users.find({ age: { $gt: 25 } });
  1. Updating a Document

db.users.updateOne(
    { email: "[email protected]" },
    { $set: { age: 30 } }
);
  1. Deleting a Document

db.users.deleteOne({ email: "[email protected]" });

MongoDB Use Cases

  • Big Data Applications

  • Real-time Analytics

  • Internet of Things (IoT)

  • Content Management Systems

  • Mobile and Web Apps

Last updated

Was this helpful?