以下最小代码尝试连接到mongod。它运行良好,但如果db将在脚本执行之前脱机,它将退出并且永远不会连接。我希望它能够尝试连接直到成功。
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);
});