2021-07-12 12:47:20 -04:00
|
|
|
const Settings = require('@overleaf/settings')
|
2020-09-03 12:05:13 -04:00
|
|
|
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,
|
2021-07-13 07:04:47 -04:00
|
|
|
waitForDb,
|
2020-09-03 12:05:13 -04:00
|
|
|
}
|