mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
3644db6848
mongojs was enabling it by default as well.
36 lines
727 B
JavaScript
36 lines
727 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.docs = internalDb.collection('docs')
|
|
db.docOps = internalDb.collection('docOps')
|
|
}
|
|
async function addCollection(name) {
|
|
await waitForDb()
|
|
const internalDb = (await clientPromise).db()
|
|
|
|
db[name] = internalDb.collection(name)
|
|
}
|
|
|
|
module.exports = {
|
|
db,
|
|
ObjectId,
|
|
addCollection,
|
|
waitForDb
|
|
}
|