From 8a1c3a4b430ede0251e536d34ee345b65262812d Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Thu, 1 Oct 2015 11:21:59 +0100 Subject: [PATCH] Better logging on database errors --- db/index.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/db/index.js b/db/index.js index 59b242f..6223947 100644 --- a/db/index.js +++ b/db/index.js @@ -4,7 +4,26 @@ var path = require("path"); var mongoose = require("mongoose"); var config = require(path.join(__dirname, "../config/config.js")); -mongoose.connect(config.mongo.uri); +var connect = function () { + mongoose.connect(config.mongo.uri, { + server: { + socketOptions: { + keepAlive: 1, + connectTimeoutMS: 30000 + } + } + }); +}; + +connect(); + +mongoose.connection.on("error", function (error) { + winston.error(error); +}); + +mongoose.connection.on("disconnected", function () { + winston.error("MongoDB: Was disconnected."); +}); // Load models require(path.join(__dirname, "/models/message")); @@ -12,4 +31,4 @@ require(path.join(__dirname, "/models/session")); require(path.join(__dirname, "/models/profile")); require(path.join(__dirname, "/models/archivedGather")); -module.exports = mongoose; \ No newline at end of file +module.exports = mongoose;