1

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)
    }

})

1 Answer 1

4

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

,function(err,err)

for example:

,function(err,connection)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.