node.js - Failing to connect to mongodb (mongolab) from nodejs app running localhost -
node.js - Failing to connect to mongodb (mongolab) from nodejs app running localhost -
i trying connect using next code. running nodejs app locally , cannot connect mongolab db using mongodb native driver. after 30sec error returned says: {"name":"mongoerror","message":"no valid seed servers in list"}
should declare else somewhere? missing? when run live on heroku connects fine. also, when run terminal (shell) connects fine.
var mongoclient = require('mongodb').mongoclient; var util = require('util'); var assert = require('assert'); var auth = { user: 'root', pass: 'blabla', host: 'blabla.mongolab.com', port: 63879, name: 'heroku_blabla' }; // connection url var url = util.format('mongodb://%s:%s@%s:%d/%s', auth.user, auth.pass, auth.host, auth.port, auth.name); // utilize connect method connect server mongoclient.connect(url, function(err, db) { assert.equal(null, err); console.log("connected correctly server"); db.close(); });
i solved it, don't know caused problem. suspected dns problem.
so went terminal , first run:
ping ds00000.mongolab.com
(change 00000 port of mongolab db)
to check host.
then run: nc -w 3 -v ds000000.mongolab.com 000000
finally, if 2 succeed not problem port. so, changed host name in code ip of host name in mongolab, , solved error appeared. note: ip of mongolab db host appears in response of sec command in terminal.
node.js mongodb heroku
Comments
Post a Comment