mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
[misc] mongodb: refactor the process of setting up the db construct
Co-Authored-By: John Lees-Miller <jdleesmiller@gmail.com>
This commit is contained in:
parent
8a8a830ad3
commit
1e7fa2246d
1 changed files with 7 additions and 3 deletions
|
@ -3,17 +3,21 @@ const { MongoClient, ObjectId } = require('mongodb')
|
|||
|
||||
const clientPromise = MongoClient.connect(Settings.mongo.url)
|
||||
|
||||
let setupDbPromise
|
||||
async function waitForDb() {
|
||||
await clientPromise
|
||||
if (!setupDbPromise) {
|
||||
setupDbPromise = setupDb()
|
||||
}
|
||||
await setupDbPromise
|
||||
}
|
||||
|
||||
const db = {}
|
||||
waitForDb().then(async function () {
|
||||
async function setupDb() {
|
||||
const internalDb = (await clientPromise).db()
|
||||
|
||||
db.docs = internalDb.collection('docs')
|
||||
db.docOps = internalDb.collection('docOps')
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
db,
|
||||
|
|
Loading…
Reference in a new issue