atp
atp

Reputation: 11

NodeJS Mongodb Connection Error "undefiend"

I am new to nodejs and mongodb. As you see below code, I am trying to connect mongodb by NodeJs but there is an

"undefined" error

Could anyone help me ?

var mongoose = require('mongoose');  
mongoose.Promise = require('bluebird');  
var mongodb = 'mongodb://localhost/yenidb';  
mongoose.connect(mongodb,{useMongoClient: true},function(err,err){

    if(err){
        console.log("mongoose error:" + err.log);
    }
    else{
        console.log("mongoose db connection status :" + mongodb)
    }

})

Upvotes: 1

Views: 50

Answers (1)

David Vicente
David Vicente

Reputation: 3111

You are declaring 2 different variables with the same name. Declare them with diffrent names:

,function(err,err)

for example:

,function(err,connection)

Upvotes: 4

Related Questions