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
Example document:
Step 1: Install MongoDB
Option 1: Local Installation
Download MongoDB Community Server
Install and start MongoDB service
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:
Check databases:
Step 3: Create / Use a Database
(Database is created when data is inserted)
Step 4: Create a Collection & Insert Data
Insert multiple documents:
Step 5: Read Data
Find all records:
Find with condition:
Pretty format:
Step 6: Update Data
Step 7: Delete Data
Delete all:
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
