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

26 lines
525 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 getCollection(name) {
return (await clientPromise).db().collection(name)
2020-08-19 08:00:01 -04:00
}
async function waitForDb() {
await clientPromise
}
const db = {}
waitForDb().then(async function () {
db.messages = await getCollection('messages')
db.rooms = await getCollection('rooms')
})
2020-08-19 08:00:01 -04:00
module.exports = {
db,
2020-08-19 08:00:01 -04:00
ObjectId,
getCollection,
waitForDb
2020-08-19 08:00:01 -04:00
}