mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-28 15:41:00 +00:00
Merge pull request #56 from overleaf/jpa-wait-for-db
[misc] simplify the naming around waiting for a mongo connection
This commit is contained in:
commit
b5e770daff
2 changed files with 12 additions and 7 deletions
|
@ -23,7 +23,8 @@ if (!module.parent) {
|
|||
settings.internal != null ? settings.internal.chat : undefined,
|
||||
(x1) => x1.host
|
||||
) || 'localhost'
|
||||
mongodb.clientConnecting
|
||||
mongodb
|
||||
.waitForDb()
|
||||
.then(() => {
|
||||
Server.server.listen(port, host, function (err) {
|
||||
if (err) {
|
||||
|
|
|
@ -1,15 +1,19 @@
|
|||
const Settings = require('settings-sharelatex')
|
||||
const { MongoClient, ObjectId } = require('mongodb')
|
||||
|
||||
const clientConnecting = MongoClient.connect(Settings.mongo.url)
|
||||
const dbPromise = clientConnecting.then((client) => client.db())
|
||||
const clientPromise = MongoClient.connect(Settings.mongo.url)
|
||||
const dbPromise = clientPromise.then((client) => client.db())
|
||||
|
||||
async function getCollection(name) {
|
||||
return (await dbPromise).collection(name)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
clientConnecting,
|
||||
ObjectId,
|
||||
getCollection
|
||||
async function waitForDb() {
|
||||
await clientPromise
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
ObjectId,
|
||||
getCollection,
|
||||
waitForDb
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue