mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
16ef0d9610
mongojs was enabling it by default as well.
37 lines
784 B
JavaScript
37 lines
784 B
JavaScript
const Settings = require('settings-sharelatex')
|
|
const { MongoClient, ObjectId } = require('mongodb')
|
|
|
|
const clientPromise = MongoClient.connect(
|
|
Settings.mongo.url,
|
|
Settings.mongo.options
|
|
)
|
|
|
|
async function healthCheck() {
|
|
const internalDb = (await clientPromise).db()
|
|
const res = await internalDb.command({ ping: 1 })
|
|
if (!res.ok) {
|
|
throw new Error('failed mongo ping')
|
|
}
|
|
}
|
|
|
|
let setupDbPromise
|
|
async function waitForDb() {
|
|
if (!setupDbPromise) {
|
|
setupDbPromise = setupDb()
|
|
}
|
|
await setupDbPromise
|
|
}
|
|
|
|
const db = {}
|
|
async function setupDb() {
|
|
const internalDb = (await clientPromise).db()
|
|
|
|
db.docSnapshots = internalDb.collection('docSnapshots')
|
|
}
|
|
|
|
module.exports = {
|
|
db,
|
|
ObjectId,
|
|
healthCheck: require('util').callbackify(healthCheck),
|
|
waitForDb
|
|
}
|