Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting to MongoDb using mongoose - Error: getaddrinfo ENOTFOUND

I have following config:

  "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'm getting such 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 have already checked answers for simular question.

I'm quite new in Mongo, but following code works fine using native 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
}

So answers for that question are not actual in my case.

like image 997
mondayguy Avatar asked Jan 12 '16 06:01

mondayguy


People also ask

How do I fix Getaddrinfo Enotfound?

The error getaddrinfo ENOTFOUND localhost is caused by Webpack cannot found localhost address. To solve it, open the terminal: sudo nano /etc/hosts. Add following into the hosts file and save it.

How do I access MongoDB over HTTP on the native driver port?

MongoDB has an uncomplicated web-based central port at 28017 by default. At the default port of 27017, there is no HTTP access. The error port is used for native driver access, not HTTP traffic. To obtain MongoDB, you'll need to use a driver like the MongoDB essential driver for NodeJS.


1 Answers

Problem in your code is that you typo here config.get('mogoose:url'). You missed a n in mongoose. Thats why you trying connect to undefined:27017

like image 175
Alexey B. Avatar answered Sep 25 '22 07:09

Alexey B.