var MongoClient = require('mongodb').MongoClient;
var url = 'mongodb://localhost:27017/mydb'
MongoClient.connect(url, function(err,db) {
if (err) {
console.log("err")
} else {
console.log("Database Connected")
}
})
.connect is striked off in VS Code
err is displayed in the VS Code terminal
Node.js node-v18.12.0-x64
Mongodb version 4.2
windows 8.1 Pro
2
Answers
Sometimes it happens to me also. I don’t use the connect function for now (macOS). Try this one:
and use it like:
await db.collection('movies').countDocuments();
Use this code. I had the same error and now it works (found this solution from this article on official mongoDb website).