overleaf/services/document-updater/app/js/mongodb.js
Christopher Hoskin f5089f596c Merge pull request #15477 from overleaf/csh-td-issue-11625-mongo-ug-5-document-updater
Upgrade mongodb module for document updater from 4.11.0 to 6.2.0

GitOrigin-RevId: 4154763ded77e04cd3f4002824fee4af8b7f8e8a
2023-12-15 09:03:38 +00:00

28 lines
685 B
JavaScript

const Metrics = require('@overleaf/metrics')
const Settings = require('@overleaf/settings')
const { MongoClient, ObjectId } = require('mongodb-legacy')
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'),
}
async function healthCheck() {
const res = await mongoDb.command({ ping: 1 })
if (!res.ok) {
throw new Error('failed mongo ping')
}
}
Metrics.mongodb.monitor(mongoClient)
module.exports = {
db,
ObjectId,
mongoClient,
healthCheck: require('util').callbackify(healthCheck),
}