Skip to main content

Query To insert data into MongoDB Database using form data by Postman

 //node es5 

var MongoClient = require('mongodb').MongoClient;

var url = "mongodb://localhost:27017/";


MongoClient.connect(url, function(err, db) {

  if (err) throw err;

  var dbo = db.db("mydb");

  //Create a collection name "customers":

  dbo.createCollection("customers", function(err, res) {

    if (err) throw err;

    console.log("Collection created!");

    db.close();

  });

});



//for express ES6


import * as mongodb from 'mongodb';

import { MongoClient } from 'mongodb'


const url ="mongodb://localhost:27017/machinetest";

MongoClient.connect(url,(err,db)=>{


            //console.log(db);

        if(err) throw err ;


        var dbo = db.db('vasu');

        const query = {name: req.body.name, email:req.body.email, password:req.body.password, mobile:req.body.mobile};

    

      dbo.collection("register").insertOne(query,(err,result)=>{


      if(err) throw err; 

      console.log(result);


      res.send('Inserted ID : '+result.insertedId);

      db.close();

    })


  });

Comments

Popular posts from this blog

Part 15- What is Repeater (Networking Devices)- Computer Networking- CCNA

Repeater  hello friends i am Vasu Birla and today i am starting new segment of CCNA computer networking  its a Networking Devices. we will discuss every important Devices used in networks. Repeater is a first networking devices. What is Repeater  Repeater is a device that receives signals and re-transmits by amplifying or regenerating signals. Repeater has two port one is for receive signals from previous network and second port is for retransmit signals to the next extended network. Two Port Repeater Repeater is a device which is used to Regenerate or replicate signal (Pichhe se aa rahe signal ko regenerate karke ya amplify karke aage strong signals bhej sakte he) Analog and digital both type of signals can be retransmitted by repeater. Here there is difference between regeneration and amplifying.  Amplification means , received signals will be amplified as it is , whether there are impurities in signals  and Regeneration means repeate...

How to Kill the Process: ( Port Process )

If you are seeing a Error like  -   Error: listen EADDRINUSE: address already in use :::3000   then you can easily kill it by running these commands  Find the Process Using Port 3006 : On Windows   netstat -ano | findstr :3000 On Linux/macOS lsof -i :3000       Terminate the Process :       On Windows taskkill /PID <PID> /F    means       taskkill /PID 17780 /F On Linux/macOS kill -9 <PID>     means kill -9 17780                ==============END ==========  

Part 19- Router (Networking Devices)- Computer Networking- CCNA

Hello friends...i am Vasu Birla and today will discuss about the most important Networking Device ..Router.  so let's start... ROUTER Router is a device which connect two or more networks together, which is why router is also known is Inter-networking device also. Inter-networking means two or more networks are connected together with the help of router. one more thing router is just like a computer  but it is designed for routing only, our computer can be router also but that are software router while hardware router which are specialize for routing is more efficient and fast than software router.  There is a Operating System installed on router which get moves data from one network to another network with the help of routing table.  Router does work on Network layer or Layer 3 of the OSI model.  Cisco Router There many companies which manufacture Router but main companies are - Cisco , Juniper , HP, 3com and Nortel  ...