TypeError: db.collection is not a function

后端 未结 18 2513
青春惊慌失措
青春惊慌失措 2020-11-27 03:09

I am trying to post data to database that I have created on mLab and I am getting this error but I don\'t know whats going wrong.I also have read previously asked question o

18条回答
  •  长情又很酷
    2020-11-27 03:31

    MongoClient.connect(db.url,(err,database) =>{
        if (err) return console.log(err)
        //require('./app/routes')(app,{});
        //try this 
         require('./app/routes')(app,database);
        app.listen(port,() => {
            console.log("We are live on"+port); 
        });
    })
    

    here you have to include the database in the empty {}.

    or

    you can also try installing mongodb to latest which will solve the issue.

    npm install mongodb@2.2.33 --save 
    

    else npm install add dependency of "mongodb": "^2.2.33" in node modules.

提交回复
热议问题