Connect to Compose.io MongoDB using SSL and mongos via Mongoose.js

I use compose.io to host mongodb test and production databases and try to connect through the node application using mongoose.js (which uses the standard nodejs mongodb driver under the hood). My connection settings 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 freeze. I do not receive an error message from the server and do not receive an "open" event.

+5
source share
1 answer

ANSWER

I managed to fix the problem by moving all the parameters from server to mongos :

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

Source: https://habr.com/ru/post/1243168/


All Articles