Hi,
I am a beginner in mongodb, trying to establish a connection to mongodb from nodejs. There is no error and it just hangs in the terminal window in VS code.
I set up the environment variable Path to C:\Program Files\MongoDB\Server\6.0\bin
and ran ‘npm install mongodb’.
“mongodb://localhost:27017/” is running in my local docker desktop.
“mongodb://localhost:27017/” succcessfully connects from Mongodb for VS code tool but not connecting from VS code nodejs. Below is my code and any help would be greatly appreciated!!
const MongoClient = require("mongodb").MongoClient;
const url = "mongodb://localhost:27017/";
//const url = "mongodb://127.0.0.1:27017";
MongoClient.connect(url, { useUnifiedTopology: true }, function (err, client) {
if (err) {
console.log("err");
} else {
console.log("Database Connected");
}
});
Thanks
Chitra