overleaf/services/notifications/app/js/mongodb.js
2021-07-13 12:04:44 +01:00

28 lines
533 B
JavaScript

const Settings = require('@overleaf/settings')
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.notifications = internalDb.collection('notifications')
}
module.exports = {
db,
ObjectId,
waitForDb,
}