mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-25 06:13:49 +00: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
74a3a95dc6
commit
9d28208870
1 changed files with 7 additions and 3 deletions
|
@ -3,16 +3,20 @@ const { MongoClient, ObjectId } = require('mongodb')
|
||||||
|
|
||||||
const clientPromise = MongoClient.connect(Settings.mongo.url)
|
const clientPromise = MongoClient.connect(Settings.mongo.url)
|
||||||
|
|
||||||
|
let setupDbPromise
|
||||||
async function waitForDb() {
|
async function waitForDb() {
|
||||||
await clientPromise
|
if (!setupDbPromise) {
|
||||||
|
setupDbPromise = setupDb()
|
||||||
|
}
|
||||||
|
await setupDbPromise
|
||||||
}
|
}
|
||||||
|
|
||||||
const db = {}
|
const db = {}
|
||||||
waitForDb().then(async function () {
|
async function setupDb() {
|
||||||
const internalDb = (await clientPromise).db()
|
const internalDb = (await clientPromise).db()
|
||||||
|
|
||||||
db.notifications = internalDb.collection('notifications')
|
db.notifications = internalDb.collection('notifications')
|
||||||
})
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
db,
|
db,
|
||||||
|
|
Loading…
Reference in a new issue