Skip to content

mongodb-crud-app with [learnwithfair, Learn with fair, Rahatul Rabbi, Md Rahatul Rabbi ,rahatulrabbi]

Notifications You must be signed in to change notification settings

learnwithfair/mongodb-crud-app

Repository files navigation

MONGODB-CRUD-APP-WITH-POSTMAN

Youtube Facebook Instagram LinkedIn

Thanks for visiting my GitHub account!

MongoDB is a document database. It stores data in a type of JSON format called BSON. Also, MongoDB is a source-available, cross-platform, document-oriented database program. Classified as a NoSQL database product, MongoDB utilizes JSON-like documents with optional schemas. see-more

CODE EXAMPLE

Source Code (Download)

Click Here

Required Software (Download)

Or Online Database (MongoDB Atlas)

========== Environment Setup ==========

  1. Install Node.js

  2. To verify installation into command form by node -v

  3. For initialization npm write the query in the command window as npm init -y

  4. Setup the opening file into the package.json and change the file with main:'server.js'

  5. To create a server using the express package then write a query into the command window as npm install express. Write code in the server file for initialization const express = require("express"); const app = express(); app.listen(3000, () => { console.log("Server is running at http:https://localhost:3000"); });

  6. Install the nodemon package for automatically running the server as- npm i --save-dev nodemon (For Developing purpose)

  7. setup the package.json file in the scripts key, write "scripts": { "start": "node ./resources/backend/server.js", "dev": "nodemon ./resources/backend/server.js", "test": "echo "Error: no test specified" && exit 1" },

  8. use the Morgan package for automatic restart. Hence install the morgan package as npm install --save-dev morgan (Development purpose) Write code in the server file for initialization const morgan = require("morgan"); app.use(morgan("dev")); --> Middlewire.

  9. Install Postman software for API testing by the URL endpoint.

  10. Install Mongobd + MongobdCompass and Mongoshell (For Database)

========== Connect MongoDB Database ==========

  1. Install Mondodb + Mongodb Compass and Mongodb Shell download from the google.
  2. Set up Environment Variable in drive:c/program file
  3. Create a directory in the base path of the c drive named data. Inside the data directory create another folder db.
  4. Write the command in the CMD window as Mongod. And write the other command in the other CMD window as mongosh.
  5. Then Check the version as mongod --version and mongosh --version.
  6. Install mongoose package as npm i mongoose
  7. Create an atlas account. In the atlas account create a cluster that have a user(as atlas admin) and network access with any access IP address.
  8. Connect the database using URL from the atlas cluster or local Mongodb compass using the mongoose package as mongoose. connect('mongodb:https://localhost:27017/database-name);

How to use this project

  • clone to your local machine
  • Run command in the Root directory
npm install
npm start
  • Import database and postman file (if Needed)
  • run the project in the postman using path -> http:https://localhost:8001

Project includes

  • Node JS
  • Express JS
  • uuid

Project Features

CRUD

  • Create -> insertOne() / insertMany()
  • Read -> find() / findOne()
  • Update -> update() / updateOne()
  • celete -> delete() / deleteOne()

Route List

  • GET: /api/products -> return all products (http:https://localhost:8001/api/products)
  • GET: /api/products/:id -> return single product(http:https://localhost:8001/api/products/product-id)
  • DELETE: /api/products/:id -> delete the product(http:https://localhost:8001/api/products/product-id)
  • PUT: /api/products/:id -> update the product(http:https://localhost:8001/api/products/product-id)
  • POST: /api/products/ -> create the product(http:https://localhost:8001/api/products/add-product)

Working Process

  1. Connect the databse
  2. Create a schema and model(collecttion/table)
  3. Create data in the databse
  4. Read data from the databse
  5. Update data from the databse
  6. Delete data from the databse

Note: create the database -> crated the collection -> create many documents

Follow Me

github facebook instagram twitter YouTube

Releases

No releases published

Packages

No packages published