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.
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
| 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. |
// 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" });Mongoose-With-Express.jsβ Main server file using Expressmodels/ToDo.jsβ Mongoose schema/model for ToDo items
npm install
node Mongoose-With-Express.jsMake sure MongoDB is running locally on default port 27017.
GET /
Creates a new ToDo document with random days and default values.
GET /a
Fetches one ToDo document and returns its title and desc.
Returns a 404 if no document is found.
Mongoose is an advanced MongoDB object modeling tool for Node.js.
- Schema-based structure and validation
- Model-based interactions
- Middleware and hooks
- Built-in query builders
| Feature | Mongoose | MongoDB Native Driver |
|---|---|---|
| Schema Support | β Yes | β No |
| Middleware | β Yes | β No |
| Easy Relationships | β Populate, References | β Manual |
| Validation | β Built-in | β Manual |
npm install mongoose| 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) |
| 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
Tutorial followed from CodeWithHarry β Haris Ali Khan πΊ Sigma Web Development Course - MongoDB + Mongoose
- π§Ύ Official MongoDB Manual
- π Mongoose Docs
- π οΈ MongoDB Playground on MongoDB Atlas
- π₯οΈ MongoDB Compass Download