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

23 lines
468 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)
2020-08-19 08:00:01 -04:00
async function waitForDb() {
await clientPromise
}
const db = {}
waitForDb().then(async function () {
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
}