2023-02-09 07:24:44 -05:00
|
|
|
const Metrics = require('@overleaf/metrics')
|
2021-07-12 12:47:15 -04:00
|
|
|
const Settings = require('@overleaf/settings')
|
2023-12-14 09:28:19 -05:00
|
|
|
const { MongoClient, ObjectId } = require('mongodb-legacy')
|
2020-08-25 07:32:16 -04:00
|
|
|
|
2024-02-22 06:03:27 -05:00
|
|
|
const mongoClient = new MongoClient(Settings.mongo.url, Settings.mongo.options)
|
2023-01-10 07:57:21 -05:00
|
|
|
const mongoDb = mongoClient.db()
|
|
|
|
|
|
|
|
const db = {
|
|
|
|
docs: mongoDb.collection('docs'),
|
|
|
|
docSnapshots: mongoDb.collection('docSnapshots'),
|
|
|
|
projects: mongoDb.collection('projects'),
|
|
|
|
}
|
2020-08-25 07:32:16 -04:00
|
|
|
|
|
|
|
async function healthCheck() {
|
2023-01-10 07:57:21 -05:00
|
|
|
const res = await mongoDb.command({ ping: 1 })
|
2020-08-25 07:32:16 -04:00
|
|
|
if (!res.ok) {
|
|
|
|
throw new Error('failed mongo ping')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-09 07:24:44 -05:00
|
|
|
Metrics.mongodb.monitor(mongoClient)
|
|
|
|
|
2020-08-25 07:32:16 -04:00
|
|
|
module.exports = {
|
|
|
|
db,
|
|
|
|
ObjectId,
|
2023-01-10 07:57:21 -05:00
|
|
|
mongoClient,
|
2024-11-08 05:21:56 -05:00
|
|
|
healthCheck: require('node:util').callbackify(healthCheck),
|
2020-08-25 07:32:16 -04:00
|
|
|
}
|