MongoDB Getting Started

MongoDB Tutorial

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

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)

SQLMongoDB
TablesCollections
RowsDocuments
ColumnsFields
Schema fixedSchema flexible
JOINsEmbedded documents

Where MongoDB is Used

  • Web applications

  • Mobile apps

  • IoT applications

  • Real-time analytics

  • Content management systems

You may also like...