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