overleaf/services/chat/app/js/mongodb.js
Jakob Ackermann 918cd0bfbe [misc] mongodb: use the new db connector by default
mongojs was enabling it by default as well.
2020-09-10 10:09:30 +01:00

29 lines
567 B
JavaScript

const Settings = require('settings-sharelatex')
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
}