overleaf/services/notifications/app/js/mongodb.js

26 lines
503 B
JavaScript
Raw Normal View History

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