overleaf/services/contacts/app/js/mongodb.js

29 lines
523 B
JavaScript
Raw Normal View History

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.contacts = internalDb.collection('contacts')
}
module.exports = {
db,
ObjectId,
2021-07-13 07:04:47 -04:00
waitForDb,
}