2020-08-31 04:58:47 -04:00
|
|
|
const Settings = require('settings-sharelatex')
|
|
|
|
const { MongoClient, ObjectId } = require('mongodb')
|
|
|
|
|
|
|
|
const clientPromise = MongoClient.connect(Settings.mongo.url)
|
|
|
|
|
2020-09-07 04:51:16 -04:00
|
|
|
let setupDbPromise
|
2020-08-31 04:58:47 -04:00
|
|
|
async function waitForDb() {
|
2020-09-07 04:51:16 -04:00
|
|
|
if (!setupDbPromise) {
|
|
|
|
setupDbPromise = setupDb()
|
|
|
|
}
|
|
|
|
await setupDbPromise
|
2020-08-31 04:58:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const db = {}
|
2020-09-07 04:51:16 -04:00
|
|
|
async function setupDb() {
|
2020-08-31 04:58:47 -04:00
|
|
|
const internalDb = (await clientPromise).db()
|
|
|
|
|
|
|
|
db.notifications = internalDb.collection('notifications')
|
2020-09-07 04:51:16 -04:00
|
|
|
}
|
2020-08-31 04:58:47 -04:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
db,
|
|
|
|
ObjectId,
|
|
|
|
waitForDb
|
|
|
|
}
|