Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 类型错误:';连接';只接受回调_Node.js_Mongodb - Fatal编程技术网

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