mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
29 lines
567 B
JavaScript
29 lines
567 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.messages = internalDb.collection('messages')
|
|
db.rooms = internalDb.collection('rooms')
|
|
}
|
|
|
|
module.exports = {
|
|
db,
|
|
ObjectId,
|
|
waitForDb,
|
|
}
|