From 86b763e3beeb1650a2ee2e4d7609060120102194 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Wed, 28 Feb 2024 10:19:03 +0000 Subject: [PATCH] Merge pull request #17327 from overleaf/em-mongo-version-startup-check Check Mongo version when starting CE/Server Pro GitOrigin-RevId: bd7d28422063f566a4afdc9de970e7f3d0b74ef6 --- .../scripts/check-mongodb.js | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/services/web/modules/server-ce-scripts/scripts/check-mongodb.js b/services/web/modules/server-ce-scripts/scripts/check-mongodb.js index 112e66e8a2..5b8fda183d 100644 --- a/services/web/modules/server-ce-scripts/scripts/check-mongodb.js +++ b/services/web/modules/server-ce-scripts/scripts/check-mongodb.js @@ -2,6 +2,8 @@ const { ObjectId } = require('mongodb') const { waitForDb, db } = require('../../../app/src/infrastructure/mongodb') const { getMongoClient } = require('../../../app/src/infrastructure/Mongoose') +const MIN_MONGO_VERSION = [5, 0] + async function main() { try { await waitForDb() @@ -9,6 +11,9 @@ async function main() { console.error('Cannot connect to mongodb') throw err } + + await checkMongoVersion() + try { await testTransactions() } catch (err) { @@ -29,6 +34,22 @@ async function testTransactions() { } } +async function checkMongoVersion() { + const mongoClient = await getMongoClient() + const buildInfo = await mongoClient.db().admin().buildInfo() + const [major, minor] = buildInfo.versionArray + const [minMajor, minMinor] = MIN_MONGO_VERSION + + if (major < minMajor || (major === minMajor && minor < minMinor)) { + const version = buildInfo.version + const minVersion = MIN_MONGO_VERSION.join('.') + console.error( + `The MongoDB server has version ${version}, but Overleaf requires at least version ${minVersion}. Aborting.` + ) + process.exit(1) + } +} + main() .then(() => { console.error('Mongodb is up.')