An open API service indexing awesome lists of open source software.

https://github.com/ksingh1817/cred-express-with-mongodb

first Express + MongoDB test deployment
https://github.com/ksingh1817/cred-express-with-mongodb

expressjs mongodb mongodb-atlas mongose nodejs

Last synced: about 1 month ago
JSON representation

first Express + MongoDB test deployment

Awesome Lists containing this project

README

          


This project is built using Express.js(render.com) and MongoDB (MongoDB Atlas).

It follows the MVC (Model-View-Controller) pattern and supports basic CRUD operations to manage student records efficiently.


Features


✅ Create Student => Add a new student to the database

📝 Edit Student => Update existing student details

❌ Delete Student => Remove a student record

👁️ View All Students => Display a list of all students

📄 View Student by ID => View detailed info of a student by ID

🔍 Search Student by Name => Filter students using a name query

📄 Pagination => Limit recode in each page

Tech Stack


Express.js => Node.js web framework for backend logic

MongoDB Atlas => Cloud-hosted NoSQL database

Random.com => Hosting the live application

GitHub => Version control and collaboration


Setting Environment


Go to => Edit the system environment variables

Go to => Environment Variables

Choose => Path on System Variables

Add => Add MongoDB URL (C:\Program Files\MongoDB\Server\8.0\bin)



Go to => Edit the system environment variables

Go to => Environment Variables

Choose => Path on User Variables

Add => Add mongosh URL (C:\Program Files\mongosh)


Install ==> mongosh

Go to ==> CMD

Hit ==> mongosh


Database Commands


show dbs ===>> Show all databases

use dbname ===>> Switch to database

db.dropDatabase() ===>> Delete current database

Collection Commands


db.createCollection("collection name") ===>> Create New Collection

show collections ===>> Show all collections

db.collection.drop("collection name") ===>> Delete a collection

db.collectionname.renameCollection("new collection name") ===>> rename collection


CRUD Operations


Insert


db.collection.insertOne({ name: "Alice", age: 25 }); // Insert one

db.collection.insertMany([{ name: "Bob" }, { name: "Carol" }]); // Insert many


Read


db.collection.find(); // All documents

db.collection.findOne({ name: "Alice" }); // First match

db.collection.find({ age: { $gt: 20 } }); // Conditional


Update


db.collection.updateOne({ name: "Alice" },{ $set: { age: 26 } }); // Update one

db.collection.updateMany({ age: { $lt: 30 } },{ $inc: { age: 1 } }); // Update many


Delete


db.collection.deleteOne({ name: "Alice" }); // Delete one

db.collection.deleteMany({ age: { $lt: 25 } }); // Delete many


Indexing


db.collection.createIndex({ name: 1 }); // Ascending index

db.collection.dropIndex("name_1");

db.collection.getIndexes();

Status Code


Success


200 OK - The request was successful and the response contains the requested data.

res.status(200).json({ message: "Success", data });



201 Created - A new resource has been successfully created (e.g., after POST).

res.status(201).json({ message: "User created", user });



204 No Content - The request was successful but there's no content to return.

res.status(204).send();



Redirection


301 Moved Permanently - A resource has been permanently moved to a new URL.

res.redirect(301, "https://newdomain.com");



302 Found - Temporary redirect.

res.redirect(302, "/login");




Client Errors


400 Bad Request - The client sent invalid data (e.g., missing fields, malformed JSON).

res.status(400).json({ error: "Invalid input" });



401 Unauthorized - Authentication is required but missing or invalid.

res.status(401).json({ error: "Authentication required" });



403 Forbidden - Authenticated user lacks permission.

res.status(403).json({ error: "Access denied" });



404 Not Found - Requested resource doesn't exist.

res.status(404).json({ error: "Resource not found" });



409 Conflict - Conflict in request (e.g., duplicate entry).

res.status(409).json({ error: "User already exists" });



422 Unprocessable Entity - Validation errors in input data.

res.status(422).json({ error: "Validation failed", details });



Server Errors


500 Internal Server Error - Unexpected server error.

res.status(500).json({ error: "Something went wrong" });



502 Bad Gateway / 503 Service Unavailable - Issues with upstream services or server overload.

res.status(503).json({ error: "Service temporarily unavailable" });