2020-08-19 08:00:01 -04:00
|
|
|
const Settings = require('settings-sharelatex')
|
|
|
|
const { MongoClient, ObjectId } = require('mongodb')
|
|
|
|
|
2020-08-24 12:06:30 -04:00
|
|
|
const clientPromise = MongoClient.connect(Settings.mongo.url)
|
2020-08-19 08:00:01 -04:00
|
|
|
|
|
|
|
async function getCollection(name) {
|
2020-08-28 04:11:33 -04:00
|
|
|
return (await clientPromise).db().collection(name)
|
2020-08-19 08:00:01 -04:00
|
|
|
}
|
|
|
|
|
2020-08-24 12:06:30 -04:00
|
|
|
async function waitForDb() {
|
|
|
|
await clientPromise
|
|
|
|
}
|
|
|
|
|
2020-08-27 11:31:27 -04:00
|
|
|
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 = {
|
2020-08-27 11:31:27 -04:00
|
|
|
db,
|
2020-08-19 08:00:01 -04:00
|
|
|
ObjectId,
|
2020-08-24 12:06:30 -04:00
|
|
|
getCollection,
|
|
|
|
waitForDb
|
2020-08-19 08:00:01 -04:00
|
|
|
}
|