Monday, 5 June 2017

mongoDB returning with HTTP 504 intermittently, Increase connection timeout in mongodb

I'm novice to mongoDB and i'm debugging an intermittent time-out error from DB.

For a particular request : /ReferenceInformationService/api/v1/parts-info

DB is returning with timeout. Should connection timeout be increased? How?

My server configuration :

 'use strict';

//change dir to this one
process.chdir(__dirname);

// Dependencies
var express = require('express'),
    expressValidator = require('express-validator'),
    MongoDb = require('../Shared/helpers/mongoDb');


var path = require('path');


var errorHandler = require('../Shared/helpers/errorHandler');

// Routes
var referenceInformationService = require('./routes/referenceInformationService');

// Start app
var app = express();
app.set('data', __dirname + '/data/');
app.use(expressValidator());


// all environments
app.set('port', process.env.PORT || 9000);
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(app.router);

app.use(express.static(path.join(__dirname, '.')));

// Error handling
if ('development' === app.get('env')) {
    app.use(express.errorHandler());
} else {
    app.use(errorHandler.handleError);
}

//Set title
process.title = 'ProductInformationService Listening on port : ' + app.get('port');

//allow cross domain
app.all('*', function (req, res, next) {
    res.header('Access-Control-Allow-Origin', '*');
    res.header('Access-Control-Allow-Headers', 'X-Requested-With');
    next();
});
//allow Private certificate
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';


// reference information services
app.post('/ReferenceInformationService/api/v1/parts-info', referenceInformationService.partsInfo);

// initialize mongo db connection then launch server listening
var mongoPort = process.env.MONGO_PORT || 27017;
var mongoHost = process.env.QQ_MONGODB_HOST || 'localhost';


MongoDb.connect('mongodb://'+mongoHost+':' + mongoPort + '/QuickQuotation', function () {
    console.log('mongodb://'+mongoHost+':' + mongoPort + '/QuickQuotation connected ');
    app.listen(app.get('port'), function () {
        console.log('> ProductInformationService server listening on port ' + app.get('port'));
    });
});



via Abhijeet Sinha

No comments:

Post a Comment