overleaf/services/chat/app/js/mongodb.js

30 lines
567 B
JavaScript
Raw Normal View History

2020-08-19 08:00:01 -04:00
const Settings = require('settings-sharelatex')
const { MongoClient, ObjectId } = require('mongodb')
const clientPromise = MongoClient.connect(
Settings.mongo.url,
Settings.mongo.options
)
2020-08-19 08:00:01 -04:00
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')
}
2020-08-19 08:00:01 -04:00
module.exports = {
db,
2020-08-19 08:00:01 -04:00
ObjectId,
waitForDb
2020-08-19 08:00:01 -04:00
}