MongoDB Getting Started

MongoDB Getting Started 🚀

What is MongoDB?

MongoDB is a NoSQL, document-oriented database that stores data in JSON-like documents (BSON) instead of tables and rows.
It is designed for high performance, scalability, and flexibility, making it popular for modern web and mobile applications.


Key Features of MongoDB

  • 📄 Document-based (stores data as documents)

  • 🔄 Schema-less (no fixed structure)

  • High performance

  • 📈 Horizontal scalability (sharding)

  • 🔐 Replication & high availability

  • 🌐 Cloud-ready (MongoDB Atlas)


MongoDB Data Structure

Database
└── Collection
└── Document

Example document:



 


Step 1: Install MongoDB

Option 1: Local Installation

  1. Download MongoDB Community Server

  2. Install and start MongoDB service

  3. MongoDB runs on port 27017 by default

Option 2: MongoDB Atlas (Cloud – Recommended)

  • Create a free cloud database

  • No installation required

  • Access from anywhere


Step 2: Start MongoDB Shell

Open terminal or command prompt:

mongosh

Check databases:

show dbs

Step 3: Create / Use a Database

use collegeDB

(Database is created when data is inserted)


Step 4: Create a Collection & Insert Data

db.students.insertOne({
name: "Amit",
age: 21,
course: "BA"
})

Insert multiple documents:

db.students.insertMany([
{ name: "Riya", age: 20 },
{ name: "Suman", age: 22 }
])

Step 5: Read Data

Find all records:

db.students.find()

Find with condition:

db.students.find({ age: 22 })

Pretty format:

db.students.find().pretty()

Step 6: Update Data

db.students.updateOne(
{ name: "Amit" },
{ $set: { age: 23 } }
)

Step 7: Delete Data

db.students.deleteOne({ name: "Riya" })

Delete all:

db.students.deleteMany({})

MongoDB Tools You Should Know

  • MongoDB Compass – GUI for database

  • MongoDB Atlas – Cloud database

  • mongosh – Command-line shell


SQL vs MongoDB (Quick Comparison)

SQL MongoDB
Tables Collections
Rows Documents
Columns Fields
Schema fixed Schema flexible
JOINs Embedded documents

Where MongoDB is Used

  • Web applications

  • Mobile apps

  • IoT applications

  • Real-time analytics

  • Content management systems

You may also like...