mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
[misc] simplify the naming around waiting for a mongo connection
Co-Authored-By: Eric Mc Sween <eric.mcsween@overleaf.com> Co-Authored-By: Miguel Serrano <mserranom@gmail.com> Co-Authored-By: Simon Detheridge <s@sd.ai>
This commit is contained in:
parent
d345911730
commit
39ea30355e
2 changed files with 12 additions and 7 deletions
|
@ -23,7 +23,8 @@ if (!module.parent) {
|
||||||
settings.internal != null ? settings.internal.chat : undefined,
|
settings.internal != null ? settings.internal.chat : undefined,
|
||||||
(x1) => x1.host
|
(x1) => x1.host
|
||||||
) || 'localhost'
|
) || 'localhost'
|
||||||
mongodb.clientConnecting
|
mongodb
|
||||||
|
.waitForDb()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
Server.server.listen(port, host, function (err) {
|
Server.server.listen(port, host, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
|
@ -1,15 +1,19 @@
|
||||||
const Settings = require('settings-sharelatex')
|
const Settings = require('settings-sharelatex')
|
||||||
const { MongoClient, ObjectId } = require('mongodb')
|
const { MongoClient, ObjectId } = require('mongodb')
|
||||||
|
|
||||||
const clientConnecting = MongoClient.connect(Settings.mongo.url)
|
const clientPromise = MongoClient.connect(Settings.mongo.url)
|
||||||
const dbPromise = clientConnecting.then((client) => client.db())
|
const dbPromise = clientPromise.then((client) => client.db())
|
||||||
|
|
||||||
async function getCollection(name) {
|
async function getCollection(name) {
|
||||||
return (await dbPromise).collection(name)
|
return (await dbPromise).collection(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
async function waitForDb() {
|
||||||
clientConnecting,
|
await clientPromise
|
||||||
ObjectId,
|
}
|
||||||
getCollection
|
|
||||||
|
module.exports = {
|
||||||
|
ObjectId,
|
||||||
|
getCollection,
|
||||||
|
waitForDb
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue