overleaf/services/document-updater/app/js/mongodb.js
Eric Mc Sween 74eeec2ba3 Merge pull request #11680 from overleaf/em-mongo-pool-monitoring
Mongo connection pool monitoring

GitOrigin-RevId: 050e50e7e67061ccbf39a710ca4532eafd423365
2023-02-09 14:34:35 +00:00

28 lines
678 B
JavaScript

const Metrics = require('@overleaf/metrics')
const Settings = require('@overleaf/settings')
const { MongoClient, ObjectId } = require('mongodb')
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),
}