overleaf/services/document-updater/app/js/mongodb.js
Eric Mc Sween f76ab26822 Merge pull request #10998 from overleaf/em-upgrade-mongo-document-updater
Upgrade Mongo driver in document updater

GitOrigin-RevId: e3c4d86bbcf86dcf16fdfdbfab2aaf0d8eb1037c
2023-01-11 09:05:28 +00:00

25 lines
595 B
JavaScript

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')
}
}
module.exports = {
db,
ObjectId,
mongoClient,
healthCheck: require('util').callbackify(healthCheck),
}