The following minimal code tries to connect to mongod. It works great, but if the db will go offline before the script will be executed, it will exit and will never connect. I want it to try to connect until success.
var http = require('http')
, mongodb = require('mongodb');
var options = {
{
uri_decode_auth: true,
numberOfRetries: 1000,
db: {
numberOfRetries: 1000,
retryMiliSeconds: 5000,
bufferMaxEntries: 0
},
server: {
auto_reconnect: true,
socketOptions: {
connectTimeoutMS: 5000,
},
reconnectTries: 1000,
reconnectInterval: 5000,
}
};
mongodb.MongoClient.connect('mongodb://username:password@127.0.0.1:27017/dbname', options, function(err, db) {
if (err) {
console.log('failure');
return;
}
console.log('success');
http.createServer(function(request, response) {
}).listen(80);
});