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

1.8k views Asked by At

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.

1

There are 1 answers

0
chas On

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
  }
}