I need to get a MongoDB connection to Node.js with Mongoose and Express to connect with SSL, but I can't connect even after knowing the keys work by connecting with Robomongo.
'use strict';
var mongoose = require('mongoose'),
fs = require('fs'),
express = require('express');
mongoose.set('debug', true);
// Bootstrap db connection
var db = mongoose.connect('mongodb://localhost/test', {
options: {
ssl: true,
port: 27017,
user: 'xxxxxxxx',
pass: 'xxxxxxxx_',
sslValidate: false,
checkServerIdentity: false,
sslCA: fs.readFileSync('./config/sslcerts/mongodb.pem'),
sslCert: fs.readFileSync('./config/sslcerts/mongodb-cert.crt'),
sslKey: fs.readFileSync('./config/sslcerts/mongodb-cert.key'),
sslPass: 'xxxxxx'
},
},
function(err) {
console.error('Could not connect to MongoDB!');
console.log(err);
});
// Init the express application
var app = require('express')(db);
app.listen(8443);
console.log('MEAN.JS application started on port ' + 8443);
Here is how I fire mongod:
$ mongod --fork --logpath mongodblogs/mongodb.log --dbpath mongodb --bind_ip 127.0.0.1 --sslMode requireSSL --sslPEMKeyFile /app/website/config/sslcerts/mongodb.pem --sslCAFile /app/website/config/sslcerts/mongodb-cert.crt -v
Errors:
Could not connect to MongoDB! MongoError: connection 0 to localhost:27017 closed
same code, sometimes with another different error:
Could not connect to MongoDB! MongoError: read ECONNRESET
Mongoose version: "raw": "mongoose@4.10.8", Node version 4.8.0
Can someone help?