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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With