2020-09-03 12:05:13 -04:00
|
|
|
const Settings = require('settings-sharelatex')
|
|
|
|
const { MongoClient, ObjectId } = require('mongodb')
|
|
|
|
|
2020-09-10 05:57:29 -04:00
|
|
|
const clientPromise = MongoClient.connect(
|
|
|
|
Settings.mongo.url,
|
|
|
|
Settings.mongo.options
|
|
|
|
)
|
2020-09-03 12:05:13 -04:00
|
|
|
|
|
|
|
let setupDbPromise
|
|
|
|
async function waitForDb() {
|
|
|
|
if (!setupDbPromise) {
|
|
|
|
setupDbPromise = setupDb()
|
|
|
|
}
|
|
|
|
await setupDbPromise
|
|
|
|
}
|
|
|
|
|
|
|
|
const db = {}
|
|
|
|
async function setupDb() {
|
|
|
|
const internalDb = (await clientPromise).db()
|
|
|
|
|
|
|
|
db.spellingPreferences = internalDb.collection('spellingPreferences')
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
db,
|
|
|
|
ObjectId,
|
|
|
|
waitForDb
|
|
|
|
}
|