Connecting to MongoDb using mongoose - Error: getaddrinfo ENOTFOUND

I have the following configuration:

"mongoose": { "url": "mongodb://127.0.0.1:27017/chat", "options": { "server": { "socketOptions": { "keepAlive": 1 } } } } 

And connect to my db

 mongoose.connect(config.get('mogoose:url'), config.get('mongoose:options')) 

But I get this error:

 node_modules/mongoose/node_modules/mongodb/lib/server.js:236 process.nextTick(function() { throw err; }) ^ Error: getaddrinfo ENOTFOUND undefined undefined:27017 at errnoException (dns.js:27:10) at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:78:26) 

I already checked the answers to the simular question .

I am very new to Mongo, but the following code works fine using my own driver:

 var MongoClient = require('mongodb').MongoClient , format = require('util').format; MongoClient.connect('mongodb://127.0.0.1:27017/chat', function(err, db) { if (err) throw err; //blabla } 

Therefore, the answers to this question are not relevant in my case.

+6
source share
1 answer

The problem in your code is that you are sealing config.get('mogoose:url') . You missed n in mongoose . This is why you are trying to connect to undefined:27017

+8
source

All Articles