0
const MongoClient = require("mongodb").MongoClient;
const assert = require("assert");
const url = "mongodb://localhost:27017";
const dbName = "fruitsDB";
const client = new MongoClient(url, { useNewUrlParser: true });
client.connect(function (err) {
    assert.equal(null, err);
    console.log("connected to the server");
    const db = client.db(dbName);
    client.close();
});

image description

This code should show in the terminal "connected to the server."

1 Answers1

0

You should use localhost ip address for connecting to mongodb. I don't know why but it was not working when i try to do with this url "mongodb://localhost:27017"

Go with this one

use const url = "mongodb://127.0.0.1:27017";

vatsal mangukiya
  • 261
  • 2
  • 14