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)
|
|
|
|
const dbPromise = clientPromise.then((client) => client.db())
|
2020-08-19 08:00:01 -04:00
|
|
|
|
|
|
|
async function getCollection(name) {
|
|
|
|
return (await dbPromise).collection(name)
|
|
|
|
}
|
|
|
|
|
2020-08-24 12:06:30 -04:00
|
|
|
async function waitForDb() {
|
|
|
|
await clientPromise
|
|
|
|
}
|
|
|
|
|
2020-08-19 08:00:01 -04:00
|
|
|
module.exports = {
|
|
|
|
ObjectId,
|
2020-08-24 12:06:30 -04:00
|
|
|
getCollection,
|
|
|
|
waitForDb
|
2020-08-19 08:00:01 -04:00
|
|
|
}
|