I have installed the Node-JS environment in D-Drive of my system.
I am trying to insert/query a record in localhost MongoDB.
Since I am already using MongoDB as a Client in VS-Code, then I am assuming that I don't need a Docker application to start a MongoDB Compass.
When I try to run the snippet, I am being encountered with the following error:
Uncaught MongoServerSelectionError MongoServerSelectionError: connect ECONNREFUSED ::1:27017
at <anonymous> (file:///D:/Udemy%20Lessons/Node%20JS-%20Udemy%20Course/node_modules/mongodb/lib/sdam/topology.js:278:38)
at listOnTimeout (node:internal/timers:569:17)
at processTimers (node:internal/timers:512:7)
Process exited with code 1".
Snippet:
`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");
var query = {name: "James Chadwick"};
dbo.collection("customers").find(query).toArray(function(err, result) {
if (err) throw err;
console.log(result);
db.close();
});
});`
From the error, it looks like the VS-Code is not connected to the MongoDB Client, although the VS-Code console reflects the localhost:27017 as connected. MongoDB Client in VS Code
Please let me know if I am missing any step of configuration. Note: I have already ran "npm install mongo" command at the Terminal.
Thank you.
Trying to connect VS-Code to MongoDB Local Client on VS-Code itself.