Skip to content

πŸš€ This repository showcases my learning journey with MongoDB and Express.js. It includes hands-on practice with creating RESTful APIs, connecting to MongoDB using Mongoose, and building a basic ToDo app. Perfect for strengthening backend development skills as part of my Full Stack Web Development path. πŸ’».

Notifications You must be signed in to change notification settings

Madhav-P-2005/MongoDB-With-Express.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“˜ MongoDB & Express.js β€” A Complete Guide

πŸ” What is MongoDB?

MongoDB is a NoSQL database that stores data in the form of documents (similar to JSON objects).
It uses a JavaScript-like syntax and is ideal for handling large volumes of unstructured or semi-structured data.


πŸ–₯️ MongoDB Compass

A GUI tool to visually manage your MongoDB databases and collections.
Use it to:

  • Create databases and collections
  • Insert, view, update, delete documents
  • Run queries without using the shell

πŸ“‚ Key Concepts

Term Description
Database Logical container for collections. Example: Sigma
Collection Like a table in SQL. Contains multiple documents. Example: Courses
Document A single record in JSON-like format inside a collection.
MongoDB Shell CLI tool to interact with MongoDB directly using commands.

πŸ§ͺ Basic MongoDB Shell Commands

// List all databases
show databases;

// Switch to or create a database
use CrudDb;

// List all collections in current database
show collections;

// View all documents inside 'courses' collection
db.courses.find();

// Insert a single document into 'courses'
db.courses.insertOne({ name: "JavaScript" });

πŸ› οΈ Project Setup: MongoDB with Express.js + Mongoose

πŸ“ Files

  • Mongoose-With-Express.js β†’ Main server file using Express
  • models/ToDo.js β†’ Mongoose schema/model for ToDo items

πŸš€ Running the Project

npm install
node Mongoose-With-Express.js

Make sure MongoDB is running locally on default port 27017.

πŸ“„ Example Endpoints

βž• Create a ToDo

GET / Creates a new ToDo document with random days and default values.

πŸ“„ Read a ToDo

GET /a Fetches one ToDo document and returns its title and desc. Returns a 404 if no document is found.


πŸ“¦ What is Mongoose?

Mongoose is an advanced MongoDB object modeling tool for Node.js.

πŸ›  Why Use Mongoose?

  • Schema-based structure and validation
  • Model-based interactions
  • Middleware and hooks
  • Built-in query builders

πŸ“Œ Key Benefits

Feature Mongoose MongoDB Native Driver
Schema Support βœ… Yes ❌ No
Middleware βœ… Yes ❌ No
Easy Relationships βœ… Populate, References ❌ Manual
Validation βœ… Built-in ❌ Manual

πŸ“¦ Install Mongoose

npm install mongoose

πŸ”„ CRUD Operations Summary

Operation Mongoose Method Description
Create save(), create() Add new document to a collection
Read find(), findOne() Retrieve document(s) from collection
Update updateOne(), findByIdAndUpdate() Modify existing document(s)
Delete deleteOne(), findByIdAndDelete() Remove document(s)

πŸ“š Useful MongoDB Operators

Operator Use Case
$set Update a field’s value
$gt, $lt Greater than, Less than filtering
$and, $or Combine multiple query conditions
$in, $nin Match values in / not in an array

🧠 Learn more :- MongoDB Query Operators


πŸ™Œ Credits

Tutorial followed from CodeWithHarry β€” Haris Ali Khan πŸ“Ί Sigma Web Development Course - MongoDB + Mongoose


πŸ”— Resources

About

πŸš€ This repository showcases my learning journey with MongoDB and Express.js. It includes hands-on practice with creating RESTful APIs, connecting to MongoDB using Mongoose, and building a basic ToDo app. Perfect for strengthening backend development skills as part of my Full Stack Web Development path. πŸ’».

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published