Thursday 1 June 2017

node.js error when trying to insert data in mongodb collection

here is the code im trying to run in linux. I've tried changing my bind ip to 0.0.0.0 and to 127.0.0.1 and even commented it but was no help. The error it displays is in screenshot here.

var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/mydb";

MongoClient.connect(url, function(err, db) {
if (err) throw err;
 var myobj = { name: "Company Inc", address: "Highway 37" };
 db.collection("customers").insertOne(myobj, function(err, res) {
  if (err) throw err;
  console.log("1 record inserted");
  db.close();
 });
  }); 

error details



via lakshay gaur

No comments:

Post a Comment