2021-07-12 16:47:21 +00:00
|
|
|
const Settings = require('@overleaf/settings')
|
2020-08-19 12:00:01 +00:00
|
|
|
const { MongoClient, ObjectId } = require('mongodb')
|
|
|
|
|
2020-09-08 14:35:22 +00:00
|
|
|
const clientPromise = MongoClient.connect(
|
|
|
|
Settings.mongo.url,
|
|
|
|
Settings.mongo.options
|
|
|
|
)
|
2020-08-19 12:00:01 +00:00
|
|
|
|
2020-09-07 08:31:50 +00:00
|
|
|
let setupDbPromise
|
2020-08-24 16:06:30 +00:00
|
|
|
async function waitForDb() {
|
2020-09-07 08:31:50 +00:00
|
|
|
if (!setupDbPromise) {
|
|
|
|
setupDbPromise = setupDb()
|
|
|
|
}
|
|
|
|
await setupDbPromise
|
2020-08-24 16:06:30 +00:00
|
|
|
}
|
|
|
|
|
2020-08-27 15:31:27 +00:00
|
|
|
const db = {}
|
2020-09-07 08:31:50 +00:00
|
|
|
async function setupDb() {
|
2020-08-28 08:26:06 +00:00
|
|
|
const internalDb = (await clientPromise).db()
|
|
|
|
|
|
|
|
db.messages = internalDb.collection('messages')
|
|
|
|
db.rooms = internalDb.collection('rooms')
|
2020-09-07 08:31:50 +00:00
|
|
|
}
|
2020-08-27 15:31:27 +00:00
|
|
|
|
2020-08-19 12:00:01 +00:00
|
|
|
module.exports = {
|
2020-08-27 15:31:27 +00:00
|
|
|
db,
|
2020-08-19 12:00:01 +00:00
|
|
|
ObjectId,
|
2020-08-24 16:06:30 +00:00
|
|
|
waitForDb
|
2020-08-19 12:00:01 +00:00
|
|
|
}
|