node.js - Mongoose gives error while connecting using mongolab uri ? -


it gives following error-

mongoose connection error:  { [mongoerror: connect einval] name: 'mongoerror', message: 'connect einval' }  /home/user/documents/oes/node_modules/connect-mongo/node_modules/mongodb/lib/server.js:228     process.nexttick(function() { throw err; })                                         ^ error: connect einval @ errnoexception (net.js:905:11) @ connect (net.js:767:19) @ net.js:846:9 @ asynccallback (dns.js:68:16) @ object.onanswer [as oncomplete] (dns.js:121:9) 

14 jun 18:04:11 - [nodemon] app crashed - waiting file changes before starting...

this old problem, no 1 has yet answered it.

we see users have problems connecting mongolab using mongoose driver. root cause incorrect configuration of driver, particularly around timeouts. following connection example using mongolab-recommended driver options:

// mongoose 4.3.x var mongoose = require('mongoose');    /*   * mongoose default sets auto_reconnect option true.  * recommend setting socket options @ both server , replica set level.  * recommend 30 second connection timeout because allows   * plenty of time in operating environments.  */ var options = { server: { socketoptions: { keepalive: 300000, connecttimeoutms: 30000 } },                  replset: { socketoptions: { keepalive: 300000, connecttimeoutms : 30000 } } };         var mongodburi = 'mongodb://user:pass@host:port/db';  mongoose.connect(mongodburi, options); var conn = mongoose.connection;               conn.on('error', console.error.bind(console, 'connection error:'));    conn.once('open', function() {   // wait database connection establish, start app.                          }); 

if doesn't help, please ensure password or username doesn't has special character, try connect via cmd first.

hope helped :)


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -