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