-->

ABOUT US

Our development agency is committed to providing you the best service.

OUR TEAM

The awesome people behind our brand ... and their life motto.

  • Kumar Atul Jaiswal

    Ethical Hacker

    Hacking is a Speed of Innovation And Technology with Romance.

  • Kumar Atul Jaiswal

    CEO Of Hacking Truth

    Loopholes are every major Security,Just need to Understand it well.

  • Kumar Atul Jaiswal

    Web Developer

    Techonology is the best way to Change Everything, like Mindset Goal.

OUR SKILLS

We pride ourselves with strong, flexible and top notch skills.

Marketing

Development 90%
Design 80%
Marketing 70%

Websites

Development 90%
Design 80%
Marketing 70%

PR

Development 90%
Design 80%
Marketing 70%

ACHIEVEMENTS

We help our clients integrate, analyze, and use their data to improve their business.

150

GREAT PROJECTS

300

HAPPY CLIENTS

650

COFFEES DRUNK

1568

FACEBOOK LIKES

STRATEGY & CREATIVITY

Phasellus iaculis dolor nec urna nullam. Vivamus mattis blandit porttitor nullam.

PORTFOLIO

We pride ourselves on bringing a fresh perspective and effective marketing to each project.

  • Make Get Delete and Put API with mongoose in Nodejs

     

    Make Get Delete and Put API with mongoose in Nodejs

     

      

    Make Get Delete and Put API with mongoose in Nodejs



    This blog we have seen mongodb basic and how is it work with installation and after installation, we have already seen mongodb basic, CRUD operation, connect mongodb with nodejs, read, update, delete, POST, GET API etc. we should not face any problem while making Database, collection(table) and using the data in nodejs even whenever we will make API. Read data from mongodb in nodejs



    • # What is Mongoose
    • # Install Mongoose
    • # Example of GET Method API
    • # Example of DELETE Method API
    • # Example of PUT Method API


     

    Now in this blog  we will use mongoose. There is an npm package to connect nodes to mongodb. Mongoose is a MongoDB object modeling tool designed to work in an asynchronous environment. They created mongoose by improving mongodb, with the help of which you can create schemas and models of mongoose's movements.

    Suppose that there are 4 fields in our database (like name, brand, price, category) and the user wants to add a 5th field also (like color) but we want to add only 4 fields, for this we create schemas.

    Here you can also define TYPE in schemas like price type is numeric but if any user wants to use quotes (" " ' ') then we can stop the user for this.

    in sort we can apply validation in mongoose but we can't in directly mongodb.

     

     

     What is MongoDB

     

    MongoDB is a popular open-source NoSQL (non-relational) database management system. NoSQL means no structure like it is look like an object while in SQL it is a structure query language like SELECT CustomerName, City FROM Customers; (The SELECT statement is used to select data from a database.) But NoSQL database is useless...NOT completely because of whenever we want add extra column in database then it is possible through NoSQL MongoDB.   

     

    MongoDB installation - CLICK HERE

    MongoDB Basic Command - CLICK HERE

    About MongoDB vs SQL - CLICK HERE

    CRUD in MongoDB - CLICK HERE

     

     



    Object Like - 

     

     

    {
      "_id": {
        "$oid": "659ad46e0382148123c82841"
      },
      "name": "moto G60",
      "brand": "motorola",
      "price": 16500,
      "category": "mobile"
    }
    
    
    

     

     


    MongoDB is a type of database that helps store and manage large amounts of data in a flexible and scalable way. Unlike SQL, MongoDB doesn't require a fixed structure for the data, allowing you to store information in a more versatile format.


    • MongoDB is a NoSQL database.
    • The data stored in a collection
    • Collection don't have row and columns
    • Data is stored in the form of object.




    Install Mongoose


    For this you need to copy this (npm i mongoose) and paste it in project's terminal.

    https://www.npmjs.com/package/mongoose

     

     

     

    Make Get Delete and Put API with mongoose in Nodejs

     

     CLICK HERE FOR POST METHOD - POST WITH MONGOOSE


    Example of GET Method API

     

    Here, we gonna write the code of get method with mongoose, you can also check the post method with mongoose. simple endpoint is our /list and we will promises (async and await)

     

     

    app.get('/list', async (req, resp) => {
       let data  = await Product.find();
       resp.send(data)
    })
    

     

     

     if we run this code with the help of nodemon index.js or node index.js you can see this.



    Make Get Delete and Put API with mongoose in Nodejs


     

     Example of DELETE Method API

     

     Now we are using delete method and inside the parameter we send the ID and through this ID we will delete the data from database.

    Here we first simple console.log(done) checking for delete method is working or not.



    app.delete('/delete/:id', async (req, resp) =>{
       console.log(req.params);
    
       resp.send("Done")
    })
    
    
    



     

    Make Get Delete and Put API with mongoose in Nodejs

     

    app.delete('/delete/:_id', async (req, resp) =>{
       console.log(req.params);
       let data = await Product.deleteOne({id : 
       req.params})
       resp.send(data)
    })
    
    

     

     

     Here we breakdown the code and /delete/:_id this _id we will get from mongoDB dont worry i will showing you and we will use deleteOne method because of we  want to delete the only one data from id number and we will get id from parameters.



    Make Get Delete and Put API with mongoose in Nodejs


    Make Get Delete and Put API with mongoose in Nodejs


     Here, is acknowledged is true thats mean data is deleted.



     

     Example of PUT Method API

     

    With the PUT Method you can change the data means update the data through the _id, name whatever you want but mostly we will delete by _id.

     

     

    app.put("/update/:_id", async (req, resp) => {
       console.log(req.params)
       let data = await Product.updateOne(
           req.params, //it is condition 
          {
             $set : req.body
          }
          );
          resp.send(data)
    })
    

     

     updateOne method and req.params (it is condition ) and second one $set is represent what do you want to update. so in postman we will update the price of id.


    Make Get Delete and Put API with mongoose in Nodejs

    Make Get Delete and Put API with mongoose in Nodejs

    Make Get Delete and Put API with mongoose in Nodejs


     


     



    Disclaimer



    All tutorials are for informational and educational purposes only and have been made using our own routers, servers, websites and other vulnerable free resources. we do not contain any illegal activity. We believe that ethical hacking, information security and cyber security should be familiar subjects to anyone using digital information and computers. Hacking Truth is against misuse of the information and we strongly suggest against it. Please regard the word hacking as ethical hacking or penetration testing every time this word is used. We do not promote, encourage, support or excite any illegal activity or hacking.

     

  • How to make Post API with mongoose in Nodejs

     

    Disclaimer   All tutorials are for informational and educational purposes only and have been made using our own routers, servers, websites and other vulnerable free resources. we do not contain any illegal activity. We believe that ethical hacking, information security and cyber security should be familiar subjects to anyone using digital information and computers. Hacking Truth is against misuse of the information and we strongly suggest against it. Please regard the word hacking as ethical hacking or penetration testing every time this word is used. We do not promote, encourage, support or excite any illegal activity or hacking.

     

    Make Post API with mongoose in Nodejs



    This blog we have seen mongodb basic and how is it work with installation and after installation, we have already seen mongodb basic, CRUD operation, connect mongodb with nodejs, read, update, delete, POST, GET API etc. we should not face any problem while making Database, collection(table) and using the data in nodejs even whenever we will make API. Read data from mongodb in nodejs



    • # What is Mongoose
    • # Install Mongoose
    • # Make Config file for MongoDB
    • # Make Post Route
    • # Get data from the postman and save in DB


     

    Now in this blog  we will use mongoose. There is an npm package to connect nodes to mongodb. Mongoose is a MongoDB object modeling tool designed to work in an asynchronous environment. They created mongoose by improving mongodb, with the help of which you can create schemas and models of mongoose's movements.

    Suppose that there are 4 fields in our database (like name, brand, price, category) and the user wants to add a 5th field also (like color) but we want to add only 4 fields, for this we create schemas.

    Here you can also define TYPE in schemas like price type is numeric but if any user wants to use quotes (" " ' ') then we can stop the user for this.

    in sort we can apply validation in mongoose but we can't in directly mongodb.

     

     

     What is MongoDB

     

    MongoDB is a popular open-source NoSQL (non-relational) database management system. NoSQL means no structure like it is look like an object while in SQL it is a structure query language like SELECT CustomerName, City FROM Customers; (The SELECT statement is used to select data from a database.) But NoSQL database is useless...NOT completely because of whenever we want add extra column in database then it is possible through NoSQL MongoDB.   

     

    MongoDB installation - CLICK HERE

    MongoDB Basic Command - CLICK HERE

    About MongoDB vs SQL - CLICK HERE

    CRUD in MongoDB - CLICK HERE

     

     



    Object Like - 

     

     

    {
      "_id": {
        "$oid": "659ad46e0382148123c82841"
      },
      "name": "moto G60",
      "brand": "motorola",
      "price": 16500,
      "category": "mobile"
    }
    
    
    

     

     


    MongoDB is a type of database that helps store and manage large amounts of data in a flexible and scalable way. Unlike SQL, MongoDB doesn't require a fixed structure for the data, allowing you to store information in a more versatile format.


    • MongoDB is a NoSQL database.
    • The data stored in a collection
    • Collection don't have row and columns
    • Data is stored in the form of object.




    Install Mongoose


    For this you need to copy this (npm i mongoose) and paste it in project's terminal.

    https://www.npmjs.com/package/mongoose

     

     

    Disclaimer   All tutorials are for informational and educational purposes only and have been made using our own routers, servers, websites and other vulnerable free resources. we do not contain any illegal activity. We believe that ethical hacking, information security and cyber security should be familiar subjects to anyone using digital information and computers. Hacking Truth is against misuse of the information and we strongly suggest against it. Please regard the word hacking as ethical hacking or penetration testing every time this word is used. We do not promote, encourage, support or excite any illegal activity or hacking.

     

     

    config.js

     

    First of all we will create a new file called as config.js and inside this file we will make connection code of mongodb and add a database name.



    const mongoose = require('mongoose');
    mongoose.connect("mongodb://127.0.0.1:27017/e-comm");
    
    
    

     

    Simply you can copy the "mongodb://127.0.0.1:27017/" from mongodb and e-comm is our database name.

     

     

    Product.js

     

    Now we can create product scheme code inside of product.js file. we have already told about schema and model.  you can check our previous tutorial.

     

     

    const mongoose = require('mongoose')
    const ProductScheme = new mongoose.Schema({
        name: String,
        brand: String,
        price: Number,
        category: String
    });
    
    
    module.exports = mongoose.model('products', ProductScheme );
    

     

     

    Here we will describe each line of code don't worry. first import the mongoose and create a ProductScheme and inside this scheme we will add from mongodb parameter that we have already used like name, brand, price, category and export with module.exports = mongoose.model('products', ProductScheme);



    index.js


    Here we go with route and create a '/create' route  and import config.js and product scheme.

     

     

    const express = require('express')
    require('./config')
    
    const product = require('./product');
    
    const app = express();
    
    app.post('/create', async (req, resp) => {
         resp.send('Done')
    })
    
    app.listen(8000)
    
    

     


    Let's breakdown the code -

     

    1) importing express

    const express = require('express');


    This line imports the Express.js framework, which simplifies the process of creating and managing a web server in Node.js.



    2) Loading Configuration:

    require('./config');


    This line seems to be importing a configuration file (presumably named 'config.js' or similar). This file may contain settings, environment variables, or any other configuration needed for the application.



    3) Importing 'product' Module:

    const product = require('./product');


    This line imports the 'product' module. The exact purpose of this module is not clear from the provided code, as it's not being used in the routes. It could be handling product-related functionality.



    4) Creating an Express Application:

    const app = express();


    This line creates an instance of the Express application, which is used to configure and define routes for your web server.



    5) Defining a POST Route:


    app.post('/create', async (req, resp) => {
        resp.send('Done');
    });



    This code sets up a route for handling HTTP POST requests to the '/create' endpoint. When a POST request is made to '/create', the server responds with the text 'Done'. The route handler is an asynchronous function, indicated by the async keyword.



    6) Starting the Server:


    app.listen(8000);




    This line starts the Express application on port 8000. The server will listen for incoming HTTP requests on this port. You can access the server by navigating to http://localhost:8000 in a web browser.




    Run with nodemon cmd


    Disclaimer   All tutorials are for informational and educational purposes only and have been made using our own routers, servers, websites and other vulnerable free resources. we do not contain any illegal activity. We believe that ethical hacking, information security and cyber security should be familiar subjects to anyone using digital information and computers. Hacking Truth is against misuse of the information and we strongly suggest against it. Please regard the word hacking as ethical hacking or penetration testing every time this word is used. We do not promote, encourage, support or excite any illegal activity or hacking.



    Now in this postman we will add json data in body section and send the data via postman but we will add two line of code.



    app.use(express.json())
    
    
       console.log(req.body)
    




    Here req.body we want to console (output) but when data is coming in req.body section before that convert into json format that's why we have to use app.use(express.json()).

     

     

    Disclaimer   All tutorials are for informational and educational purposes only and have been made using our own routers, servers, websites and other vulnerable free resources. we do not contain any illegal activity. We believe that ethical hacking, information security and cyber security should be familiar subjects to anyone using digital information and computers. Hacking Truth is against misuse of the information and we strongly suggest against it. Please regard the word hacking as ethical hacking or penetration testing every time this word is used. We do not promote, encourage, support or excite any illegal activity or hacking.






    Now we will store the data in mongodb database.

     

       let data = new Product(req.body)
       let result = await data.save();
       console.log(result)
       resp.send(result)
       
    
    

     

    Here, we will add new keyword with (req.body) and data save in DB so data.save(); and it's return the promise thats why we will await async. Finally we will get output.

     

     

    Disclaimer   All tutorials are for informational and educational purposes only and have been made using our own routers, servers, websites and other vulnerable free resources. we do not contain any illegal activity. We believe that ethical hacking, information security and cyber security should be familiar subjects to anyone using digital information and computers. Hacking Truth is against misuse of the information and we strongly suggest against it. Please regard the word hacking as ethical hacking or penetration testing every time this word is used. We do not promote, encourage, support or excite any illegal activity or hacking.

     

     

    Disclaimer   All tutorials are for informational and educational purposes only and have been made using our own routers, servers, websites and other vulnerable free resources. we do not contain any illegal activity. We believe that ethical hacking, information security and cyber security should be familiar subjects to anyone using digital information and computers. Hacking Truth is against misuse of the information and we strongly suggest against it. Please regard the word hacking as ethical hacking or penetration testing every time this word is used. We do not promote, encourage, support or excite any illegal activity or hacking.

     

     



    Disclaimer



    All tutorials are for informational and educational purposes only and have been made using our own routers, servers, websites and other vulnerable free resources. we do not contain any illegal activity. We believe that ethical hacking, information security and cyber security should be familiar subjects to anyone using digital information and computers. Hacking Truth is against misuse of the information and we strongly suggest against it. Please regard the word hacking as ethical hacking or penetration testing every time this word is used. We do not promote, encourage, support or excite any illegal activity or hacking.

     


  • CRUD operation with Mongoose

     

    CRUD operation with Mongoose

     

     

    CRUD operation with Mongoose



    This blog we have seen mongodb basic and how is it work with installation and after installation, we have already seen mongodb basic, CRUD operation, connect mongodb with nodejs, read, update, delete, POST, GET API etc. we should not face any problem while making Database, collection(table) and using the data in nodejs even whenever we will make API. Read data from mongodb in nodejs



    • # What is Mongoose
    • # Install Mongoose
    • # Create Record
    • # Update Record
    • # Delete Records 


     

    Now in this blog  we will use mongoose. There is an npm package to connect nodes to mongodb. Mongoose is a MongoDB object modeling tool designed to work in an asynchronous environment. They created mongoose by improving mongodb, with the help of which you can create schemas and models of mongoose's movements.

    Suppose that there are 4 fields in our database (like name, brand, price, category) and the user wants to add a 5th field also (like color) but we want to add only 4 fields, for this we create schemas.

    Here you can also define TYPE in schemas like price type is numeric but if any user wants to use quotes (" " ' ') then we can stop the user for this.

    in sort we can apply validation in mongoose but we can't in directly mongodb.

     

     

     What is MongoDB

     

    MongoDB is a popular open-source NoSQL (non-relational) database management system. NoSQL means no structure like it is look like an object while in SQL it is a structure query language like SELECT CustomerName, City FROM Customers; (The SELECT statement is used to select data from a database.) But NoSQL database is useless...NOT completely because of whenever we want add extra column in database then it is possible through NoSQL MongoDB.   

     

    MongoDB installation - CLICK HERE

    MongoDB Basic Command - CLICK HERE

    About MongoDB vs SQL - CLICK HERE

    CRUD in MongoDB - CLICK HERE

     

     



    Object Like - 

     

     

    {
      "_id": {
        "$oid": "659ad46e0382148123c82841"
      },
      "name": "moto G60",
      "brand": "motorola",
      "price": 16500,
      "category": "mobile"
    }
    
    
    

     

     


    MongoDB is a type of database that helps store and manage large amounts of data in a flexible and scalable way. Unlike SQL, MongoDB doesn't require a fixed structure for the data, allowing you to store information in a more versatile format.


    • MongoDB is a NoSQL database.
    • The data stored in a collection
    • Collection don't have row and columns
    • Data is stored in the form of object.




    Install Mongoose


    For this you need to copy this (npm i mongoose) and paste it in project's terminal.

    https://www.npmjs.com/package/mongoose

     

     

    CRUD operation with Mongoose



    Create Record


    Here we now are ready to implement schemas for validate extra field when user wants to enter extra field. Even first we create a record.



    const mongoose = require('mongoose');
    
    
    const saveInDB = async () => {
          await mongoose.connect("mongodb://127.0.0.1:27017/e-comm");
    
          const ProductSchemas = new mongoose.Schema({
            name: String,
    
          });
    
           
          const ProductModel = mongoose.model('products', ProductSchemas );
          let data = new ProductModel({
            name: "Atul"
          });
        
          let result = await data.save();
          console.log(result)
    
    }
    
    saveInDB()
    
    
    
    
    


    Run with nodemon (we are already installed nodemon). By default index.js file.



    CRUD operation with Mongoose


    Update Record


    Now we are ready to update the data in Database.



      const UpdateInDB = async () => {
          const Product = mongoose.model('products', ProductScheme);
          let data = await Product.updateOne(
             {name: "Atul"},
             {
                $set : {price: 41529}
             }
          )
          console.log("updated" , data)
       }
       
    UpdateInDB()   
       
    



    Run with nodemon (by default index.js run when you run command nodemon)



    CRUD operation with Mongoose



    Delete Records


    Now with the help of deleteOne({}) we can delete the one record.

     


    CRUD operation with Mongoose



    Read Data


    const ReadInDB = async () => {
      const Product = mongoose.model('product', ProductScheme);
      let data = await Product.find({name: 'oppo m40'
         
      })
      console.log("Read from database", data)
    }
    
    ReadInDB()
    



    CRUD operation with Mongoose



    Disclaimer



    All tutorials are for informational and educational purposes only and have been made using our own routers, servers, websites and other vulnerable free resources. we do not contain any illegal activity. We believe that ethical hacking, information security and cyber security should be familiar subjects to anyone using digital information and computers. Hacking Truth is against misuse of the information and we strongly suggest against it. Please regard the word hacking as ethical hacking or penetration testing every time this word is used. We do not promote, encourage, support or excite any illegal activity or hacking.

     



  • Mongoose with Node js

     

    Mongoose with Node js


    Mongoose with Node js



    This blog we have seen mongodb basic and how is it work with installation and after installation, we have already seen mongodb basic, CRUD operation, connect mongodb with nodejs, read, update, delete, POST, GET API etc. we should not face any problem while making Database, collection(table) and using the data in nodejs even whenever we will make API. Read data from mongodb in nodejs



    • # What is Mongoose
    • # Difference between Mongoose vs MongoDB package
    • # Install Mongoose
    • # What is schemas
    • # What is Model
    • # Connect Node js and MongoDB with Mongoose 


     

    Now in this blog  we will use mongoose. There is an npm package to connect nodes to mongodb. Mongoose is a MongoDB object modeling tool designed to work in an asynchronous environment. They created mongoose by improving mongodb, with the help of which you can create schemas and models of mongoose's movements.

    Suppose that there are 4 fields in our database (like name, brand, price, category) and the user wants to add a 5th field also (like color) but we want to add only 4 fields, for this we create schemas.

    Here you can also define TYPE in schemas like price type is numeric but if any user wants to use quotes (" " ' ') then we can stop the user for this.

    in sort we can apply validation in mongoose but we can't in directly mongodb.

    Model - Connect nodejs with mongodb as called as Modal.

     

     What is MongoDB

     

    MongoDB is a popular open-source NoSQL (non-relational) database management system. NoSQL means no structure like it is look like an object while in SQL it is a structure query language like SELECT CustomerName, City FROM Customers; (The SELECT statement is used to select data from a database.) But NoSQL database is useless...NOT completely because of whenever we want add extra column in database then it is possible through NoSQL MongoDB.   

     

    MongoDB installation - CLICK HERE

    MongoDB Basic Command - CLICK HERE

    About MongoDB vs SQL - CLICK HERE

    CRUD in MongoDB - CLICK HERE

     

     



    Object Like - 

     

     

    {
      "_id": {
        "$oid": "659ad46e0382148123c82841"
      },
      "name": "moto G60",
      "brand": "motorola",
      "price": 16500,
      "category": "mobile"
    }
    
    
    

     

     


    MongoDB is a type of database that helps store and manage large amounts of data in a flexible and scalable way. Unlike SQL, MongoDB doesn't require a fixed structure for the data, allowing you to store information in a more versatile format.


    • MongoDB is a NoSQL database.
    • The data stored in a collection
    • Collection don't have row and columns
    • Data is stored in the form of object.




    Install Mongoose


    For this you need to copy this (npm i mongoose) and paste it in project's terminal.

    https://www.npmjs.com/package/mongoose

     


    Mongoose with Node js



    Difference between in Schemas and Modal


    Schemas mean as many fields as there are in our database, we define them because as many fields as we have in our database, any user can enter those fields. These define the workings of our schemas.

    And in model we connect nodes to mongodb with the help of schemas.


    Here we now are ready to implement schemas for validate extra field when user wants to enter extra field.



    const mongoose = require('mongoose');
    
    
    const main = async () => {
          await mongoose.connect("mongodb://127.0.0.1:27017/e-comm");
    
          const ProductSchemas = new mongoose.Schema({
            name: String,
    
          });
    
           
          const ProductModel = mongoose.model('products', ProductSchemas );
          let data = new ProductModel({
            name: "Atul"
          });
        
          let result = await data.save();
          console.log(result)
    
    }
    
    main()
    


    Run with nodemon (we are already installed nodemon). By default index.js file.



    Mongoose with Node js


    if we add extra field but not in schemas so we can't add in mongodb.



    Mongoose with Node js





    Disclaimer



    All tutorials are for informational and educational purposes only and have been made using our own routers, servers, websites and other vulnerable free resources. we do not contain any illegal activity. We believe that ethical hacking, information security and cyber security should be familiar subjects to anyone using digital information and computers. Hacking Truth is against misuse of the information and we strongly suggest against it. Please regard the word hacking as ethical hacking or penetration testing every time this word is used. We do not promote, encourage, support or excite any illegal activity or hacking.

     


  • PUT API Update data in MongoDB

     

    PUT API  Update data in MongoDB

     

     

    PUT API  Update data in MongoDB



    This blog and in upcoming blog we will see mongodb basic and how is it work with installation and after installation we should not face any problem while making Database, collection(table) and using the data in nodejs even whenever we will make API. Read data from mongodb in nodejs



    • # Make PUT method for API
    • # Send data from postman
    • # Handle data in nodejs by request
    • # Write code for update data in MongoDB


     

    Now in this blog we will consider about mongoDB basic command which we can use to create Database, collection etc.


     

     What is MongoDB

     

    MongoDB is a popular open-source NoSQL (non-relational) database management system. NoSQL means no structure like it is look like an object while in SQL it is a structure query language like SELECT CustomerName, City FROM Customers; (The SELECT statement is used to select data from a database.) But NoSQL database is useless...NOT completely because of whenever we want add extra column in database then it is possible through NoSQL MongoDB.   

     

    MongoDB installation - CLICK HERE

    MongoDB Basic Command - CLICK HERE

    About MongoDB vs SQL - CLICK HERE

    CRUD in MongoDB - CLICK HERE

     

     



    Object Like - 

     

     

    {
      "_id": {
        "$oid": "659ad46e0382148123c82841"
      },
      "name": "moto G60",
      "brand": "motorola",
      "price": 16500,
      "category": "mobile"
    }
    
    
    

     

     


    MongoDB is a type of database that helps store and manage large amounts of data in a flexible and scalable way. Unlike SQL, MongoDB doesn't require a fixed structure for the data, allowing you to store information in a more versatile format.


    • MongoDB is a NoSQL database.
    • The data stored in a collection
    • Collection don't have row and columns
    • Data is stored in the form of object.





     

    Make new file for API

     

    If you remember, we wrote the code for database connection and data reading in the same file. if you write coding of insert, update, delete in same function and same file then it will be very complex. so that's why we will separate file of mongoDB connection file. Like this - 

     

    mongodb.js

     

     

    const { MongoClient } = require('mongodb');
    const uri = 'mongodb://127.0.0.1:27017/';
    const client = new MongoClient(uri);
    const dbName = 'e-comm';
    
    async function dbConnect()
    {
        //handle promises
        let result = await client.connect();
        console.log(result)
        db = result.db(dbName);  
        return db.collection("products")
    }
    
    module.exports = dbConnect;
    

     

     

     

    Make PUT method for API

     

    Here we are updating data in our MongoDB database by PUT method. So, first we simply add put method with resp.send({result : "updated"}).

     

     

    app.put('/', (req, resp)  => {
            
           resp.send({result : "updated"})
    })
    

     

     

     

    After running this code with nodemon api.js and check in postman.

     

     

    PUT API  Update data in MongoDB


     

     if we get the data from postman body with the code (req.body) you can simply add the JSON code in postman body section and in our code we will add console.log(req.body) .


    app.put('/', (req, resp)  => {
           
           console.log(req.body)
            resp.send({result : "updated"})
           
    
    })
    



    PUT API  Update data in MongoDB

     

     

    Now with static data we can change the price in mongoDB through postman. Like this

    Before - 

     

     


     

     

     

    app.put('/', async (req, resp)  => {
            
        let data = await dbConnect();
        let result = data.updateOne(
            {name : "samsung m40"},
            { $set : {price : 4444}}
            )
            resp.send({result : "updated"})
           
    
    })
    
    

     

    Go to postman and hit send button and check in mongoDB 

     

     

    After - 

     

     

    PUT API  Update data in MongoDB

     

     

     

    Now with the dynamic data we can change the price (whatever you want to change) so simple add the {$set : req.body} and send the data by postman.

     

     

    app.put('/', async (req, resp)  => {
          
        let data = await dbConnect();
        let result = data.updateOne(
            {name : "samsung m40"},
            { $set : req.body}
            )
            resp.send({result : "updated"})
           
    
    })
    
    

     

     

     

    PUT API  Update data in MongoDB

     

     Whole Code

     

     

    const express = require("express");
    const dbConnect = require("./mongodb/mongodb");
    
    const app = express();
    
    app.use(express.json());
    
    app.put("/", async (req, resp) => {
      let data = await dbConnect();
      let result = data.updateOne({ name: "samsung m40" }, { $set: req.body });
      resp.send({ result: "updated" });
    });
    
    app.listen(5000);
    
    
    

     

     


    Disclaimer



    All tutorials are for informational and educational purposes only and have been made using our own routers, servers, websites and other vulnerable free resources. we do not contain any illegal activity. We believe that ethical hacking, information security and cyber security should be familiar subjects to anyone using digital information and computers. Hacking Truth is against misuse of the information and we strongly suggest against it. Please regard the word hacking as ethical hacking or penetration testing every time this word is used. We do not promote, encourage, support or excite any illegal activity or hacking.

     

     

     

  • Post API insert data in MongoDB

     

    Post API insert data in MongoDB


     

    Post API insert data in MongoDB



    This blog and in upcoming blog we will see mongodb basic and how is it work with installation and after installation we should not face any problem while making Database, collection(table) and using the data in nodejs even whenever we will make API. Read data from mongodb in nodejs



    • # Read Data from MongoDB
    • # Make file for db connection
    • # Handle Promise 


     

    Now in this blog we will consider about mongoDB basic command which we can use to create Database, collection etc.


     

     What is MongoDB

     

    MongoDB is a popular open-source NoSQL (non-relational) database management system. NoSQL means no structure like it is look like an object while in SQL it is a structure query language like SELECT CustomerName, City FROM Customers; (The SELECT statement is used to select data from a database.) But NoSQL database is useless...NOT completely because of whenever we want add extra column in database then it is possible through NoSQL MongoDB.   

     

    MongoDB installation - CLICK HERE

    MongoDB Basic Command - CLICK HERE

    About MongoDB vs SQL - CLICK HERE

    CRUD in MongoDB - CLICK HERE

     

     



    Object Like - 

     

     

    {
      "_id": {
        "$oid": "659ad46e0382148123c82841"
      },
      "name": "moto G60",
      "brand": "motorola",
      "price": 16500,
      "category": "mobile"
    }
    
    
    

     

     


    MongoDB is a type of database that helps store and manage large amounts of data in a flexible and scalable way. Unlike SQL, MongoDB doesn't require a fixed structure for the data, allowing you to store information in a more versatile format.


    • MongoDB is a NoSQL database.
    • The data stored in a collection
    • Collection don't have row and columns
    • Data is stored in the form of object.





     

    Make new file for API

     

    If you remember, we wrote the code for database connection and data reading in the same file. if you write coding of insert, update, delete in same function and same file then it will be very complex. so that's why we will separate file of mongoDB connection file. Like this - 

     

    mongodb.js

     

     

    const { MongoClient } = require('mongodb');
    const uri = 'mongodb://127.0.0.1:27017/';
    const client = new MongoClient(uri);
    const dbName = 'e-comm';
    
    async function dbConnect()
    {
        //handle promises
        let result = await client.connect();
        console.log(result)
        db = result.db(dbName);  
        return db.collection("products")
    }
    
    module.exports = dbConnect;
    

     

     

    Now after making a new file (api.js) we will write code for get api.

     

     

    app.post('/', async (req, resp) => {
        resp.send({ name: "Atul Kumar" })
    })
    
    

     

     

    if we test this API  in postmand like this http:localhost:5000/ with post method.

    you can simple run this api with nodemon api.js

     

     

    Post API insert data in MongoDB

     

     

     

    Post API insert data in MongoDB

     


     

    According to above the image if we give json data in postman then how can we know this data comes or not in nodejs. so for this we will some changes and add middleware.


    this middleware used for (app.use(express.json()) - convert data in json format in nodejs.


    app.post('/', async (req, resp) => {
        console.log(req.body)
        resp.send({ name: "Atul Kumar" })
    })
    
    


    console.log(req.body) 

     

    if we send the data from postman then we can check that in your vs code terminal.


    Post API insert data in MongoDB


    Now how can we saved this data in MongoDB



    app.post('/', async (req, resp) => {
    
        let data = await dbConnect();
        let result = await data.insertOne(req.body);
        
        resp.send(result)
    })
    

     

     

     

     

    Post API insert data in MongoDB

     

     After send the data using postman and check the mongodb.

     

     

    Post API insert data in MongoDB

     

     

     


    Post API insert data in MongoDB


     

     


    Disclaimer



    All tutorials are for informational and educational purposes only and have been made using our own routers, servers, websites and other vulnerable free resources. we do not contain any illegal activity. We believe that ethical hacking, information security and cyber security should be familiar subjects to anyone using digital information and computers. Hacking Truth is against misuse of the information and we strongly suggest against it. Please regard the word hacking as ethical hacking or penetration testing every time this word is used. We do not promote, encourage, support or excite any illegal activity or hacking.

     



     

  • WHAT WE DO

    We've been developing corporate tailored services for clients for 30 years.

    CONTACT US

    For enquiries you can contact us in several different ways. Contact details are below.

    Hacking Truth.in

    • Street :Road Street 00
    • Person :Person
    • Phone :+045 123 755 755
    • Country :POLAND
    • Email :contact@heaven.com

    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation.