为什么我不能使用Node连接到本地MongoDB,可能有哪些解释?
我尝试使用本机驱动程序。
还尝试使用猫鼬。结果相同.... *(猫鼬readyState永远保持为2)。
完全不连接。但是可以使用罗盘或mongo控制台创建数据库和集合。这样就可以了。
没有运行App.js
。有什么帮助吗?
重新安装节点会有所帮助吗?即时通讯窗口,顺便说一下... Windows 10,节点v12.18.0,Mongodb 4.2.8
var MongoClient = require('mongodb').MongoClient;
console.log("We are not connected yet");
// Connect to the db
MongoClient.connect("mongodb://localhost:27017/exampleDb", function(err, db) {
//its like never entering to callback!
if (!err) {
console.log("We are connected");
}
if (err) {
console.log("Error is " + err); //never gets here, nothing printed
}
});
控制台只说:
我们尚未连接