overleaf/services/contacts/app/js/mongodb.js
2020-09-07 09:32:39 +01:00

25 lines
493 B
JavaScript

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.contacts = internalDb.collection('contacts')
}
module.exports = {
db,
ObjectId,
waitForDb
}