Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting to Compose.io MongoDB deployment using SSL and mongos through Mongoose.js

I'm using compose.io for hosting test and production mongodb databases and am attempting to connect through a node app using mongoose.js (which uses the standard nodejs mongodb driver under the hood). My connection options are as follows:

var connectionString = 'mongodb://user:password@host1:port1,host2:port2/dbname?ssl=true';

var options = {
  mongos: true,
  server: {
    ssl: true,
    sslValidate: true,
    sslCA: [fs.readFileSync('/path/to/cert/certificate.pem')] // cert from compose.io dashboard
  }
}

mongoose.createConnection(connectionString, options);

The connection just seems to hang, though. I don't receive an error from the server, nor do I receive an 'open' event.

like image 536
chas Avatar asked Feb 16 '16 18:02

chas


1 Answers

ANSWER

I was able to fix the issue by moving all of the options from server into mongos:

var options = {
  mongos: {
    ssl: true,
    sslValidate: true,
    sslCA: [fs.readFileSync('/path/to/cert/certificate.pem')] // cert from compose.io dashboard
  }
}
like image 82
chas Avatar answered Oct 18 '22 09:10

chas