From 2c99f420a33ae9b0e5b6de7c69ce67010523866d Mon Sep 17 00:00:00 2001 From: Miodec Date: Tue, 18 Jan 2022 15:42:56 +0100 Subject: [PATCH] shortened mongo connection timeout --- backend/init/mongodb.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/init/mongodb.js b/backend/init/mongodb.js index 2950ed94e..23d2688a8 100644 --- a/backend/init/mongodb.js +++ b/backend/init/mongodb.js @@ -7,6 +7,8 @@ module.exports = { let options = { useNewUrlParser: true, useUnifiedTopology: true, + connectTimeoutMS: 2000, + serverSelectionTimeoutMS: 2000, }; if (process.env.DB_USERNAME && process.env.DB_PASSWORD) { @@ -29,12 +31,12 @@ module.exports = { mongoClient = client; }) .catch((e) => { - console.log(e); + console.error(e.message); + console.error("FAILED TO CONNECT TO DATABASE. EXITING..."); process.exit(1); }); }, mongoDB() { - if (!mongoClient) throw new Error("Could not connect to the database"); return mongoClient.db(process.env.DB_NAME); }, };