Node.js 类型错误:';连接';只接受回调
当我尝试Node.js 类型错误:';连接';只接受回调,node.js,mongodb,Node.js,Mongodb,当我尝试node index.js时,我的错误是TypeError:“connect”只接受回调,然后我对如何解决这个问题感到困惑。 错误会转到mongo_client.js:165:11 我做了一个关于如何使用Nodejs连接mongodb的教程,但是我发现了一个ppl从现在起就没有遇到过的问题 const mongodb = require('mongodb'); const MongoClient = mongodb.MongoClient(); const url = 'mongodb:
node index.js
时,我的错误是TypeError:“connect”只接受回调
,然后我对如何解决这个问题感到困惑。
错误会转到mongo_client.js:165:11
我做了一个关于如何使用Nodejs连接mongodb的教程,但是我发现了一个ppl从现在起就没有遇到过的问题
const mongodb = require('mongodb');
const MongoClient = mongodb.MongoClient();
const url = 'mongodb://localhost:27107/testedmtdev';
MongoClient.connect(url, function(err, client){
if(err){
console.log('Unable to connect to the Mongodb server. Error : ', err);
} else {
app.listen(3000, ()=>{
console.log('Connected to mongodb, webservice running on port 3000');
})
}
});
我希望输出“连接到mongodb,在端口3000上运行webservice”这是因为您实际上调用的是没有参数的
MongoClient
const mongodb = require('mongodb');
const MongoClient = mongodb.MongoClient(); // <-- your calling the method here
const mongodb=require('mongodb');
const MongoClient=mongodb.MongoClient()//
const mongodb = require('mongodb');
const MongoClient = mongodb.MongoClient; // <-- do *not* call method