overleaf/services/spelling/app/js/mongodb.js

29 lines
545 B
JavaScript
Raw Normal View History

const Settings = require('settings-sharelatex')
const { MongoClient, ObjectId } = require('mongodb')
const clientPromise = MongoClient.connect(
Settings.mongo.url,
Settings.mongo.options
)
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
}