mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-22 19:11:33 +03:00
UBERF-7749: Use MONGO_OPTIONS properly (#6200)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
parent
b6af63fcb0
commit
ce807a4a28
@ -73,7 +73,7 @@ import task, { type ProjectType, type Task, type TaskType } from '@hcengineering
|
||||
import { updateYDocContent } from '@hcengineering/text'
|
||||
import tracker from '@hcengineering/tracker'
|
||||
import { deepEqual } from 'fast-equals'
|
||||
import { type Db, MongoClient } from 'mongodb'
|
||||
import { type Db } from 'mongodb'
|
||||
|
||||
export async function cleanWorkspace (
|
||||
ctx: MeasureContext,
|
||||
@ -157,10 +157,10 @@ export async function cleanWorkspace (
|
||||
}
|
||||
}
|
||||
|
||||
const client = new MongoClient(mongoUrl)
|
||||
const client = getMongoClient(mongoUrl)
|
||||
try {
|
||||
await client.connect()
|
||||
const db = getWorkspaceDB(client, workspaceId)
|
||||
const _client = await client.getClient()
|
||||
const db = getWorkspaceDB(_client, workspaceId)
|
||||
|
||||
if (opt.removedTx) {
|
||||
const txes = await db.collection(DOMAIN_TX).find({}).toArray()
|
||||
@ -173,7 +173,7 @@ export async function cleanWorkspace (
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
await client.close()
|
||||
client.close()
|
||||
}
|
||||
} catch (err: any) {
|
||||
console.trace(err)
|
||||
@ -420,10 +420,10 @@ export async function fixSkills (
|
||||
const connection = (await connect(transactorUrl, workspaceId, undefined, {
|
||||
mode: 'backup'
|
||||
})) as unknown as CoreClient & BackupClient
|
||||
const client = new MongoClient(mongoUrl)
|
||||
const client = getMongoClient(mongoUrl)
|
||||
try {
|
||||
await client.connect()
|
||||
const db = getWorkspaceDB(client, workspaceId)
|
||||
const _client = await client.getClient()
|
||||
const db = getWorkspaceDB(_client, workspaceId)
|
||||
|
||||
async function fixCount (): Promise<void> {
|
||||
console.log('fixing ref-count...')
|
||||
@ -664,7 +664,7 @@ export async function fixSkills (
|
||||
} catch (err: any) {
|
||||
console.trace(err)
|
||||
} finally {
|
||||
await client.close()
|
||||
client.close()
|
||||
await connection.close()
|
||||
}
|
||||
}
|
||||
@ -689,10 +689,10 @@ export async function restoreRecruitingTaskTypes (
|
||||
mode: 'backup',
|
||||
model: 'upgrade'
|
||||
})) as unknown as CoreClient & BackupClient
|
||||
const client = new MongoClient(mongoUrl)
|
||||
const client = getMongoClient(mongoUrl)
|
||||
try {
|
||||
await client.connect()
|
||||
const db = getWorkspaceDB(client, workspaceId)
|
||||
const _client = await client.getClient()
|
||||
const db = getWorkspaceDB(_client, workspaceId)
|
||||
|
||||
// Query all vacancy project types creations (in Model)
|
||||
// We only update new project types in model here and not old ones in spaces
|
||||
@ -839,7 +839,7 @@ export async function restoreRecruitingTaskTypes (
|
||||
} catch (err: any) {
|
||||
console.trace(err)
|
||||
} finally {
|
||||
await client.close()
|
||||
client.close()
|
||||
await connection.close()
|
||||
}
|
||||
}
|
||||
@ -853,10 +853,10 @@ export async function restoreHrTaskTypesFromUpdates (
|
||||
mode: 'backup',
|
||||
model: 'upgrade'
|
||||
})) as unknown as CoreClient & BackupClient
|
||||
const client = new MongoClient(mongoUrl)
|
||||
const client = getMongoClient(mongoUrl)
|
||||
try {
|
||||
await client.connect()
|
||||
const db = getWorkspaceDB(client, workspaceId)
|
||||
const _client = await client.getClient()
|
||||
const db = getWorkspaceDB(_client, workspaceId)
|
||||
const hierarchy = connection.getHierarchy()
|
||||
const descr = connection.getModel().getObject(recruit.descriptors.VacancyType)
|
||||
const knownCategories = [
|
||||
@ -1047,7 +1047,7 @@ export async function restoreHrTaskTypesFromUpdates (
|
||||
} catch (err: any) {
|
||||
console.trace(err)
|
||||
} finally {
|
||||
await client.close()
|
||||
client.close()
|
||||
await connection.close()
|
||||
}
|
||||
}
|
||||
|
@ -15,9 +15,8 @@
|
||||
|
||||
import { Client as ElasticClient } from '@elastic/elasticsearch'
|
||||
import core, { DOMAIN_DOC_INDEX_STATE, toWorkspaceString, type WorkspaceId } from '@hcengineering/core'
|
||||
import { getWorkspaceDB } from '@hcengineering/mongo'
|
||||
import { getMongoClient, getWorkspaceDB } from '@hcengineering/mongo'
|
||||
import { type StorageAdapter } from '@hcengineering/server-core'
|
||||
import { MongoClient } from 'mongodb'
|
||||
|
||||
export async function rebuildElastic (
|
||||
mongoUrl: string,
|
||||
@ -25,15 +24,15 @@ export async function rebuildElastic (
|
||||
storageAdapter: StorageAdapter,
|
||||
elasticUrl: string
|
||||
): Promise<void> {
|
||||
const client = new MongoClient(mongoUrl)
|
||||
const client = getMongoClient(mongoUrl)
|
||||
try {
|
||||
await client.connect()
|
||||
const db = getWorkspaceDB(client, workspaceId)
|
||||
const _client = await client.getClient()
|
||||
const db = getWorkspaceDB(_client, workspaceId)
|
||||
await db
|
||||
.collection(DOMAIN_DOC_INDEX_STATE)
|
||||
.updateMany({ _class: core.class.DocIndexState }, { $set: { elastic: false } })
|
||||
} finally {
|
||||
await client.close()
|
||||
client.close()
|
||||
}
|
||||
|
||||
await dropElastic(elasticUrl, workspaceId)
|
||||
|
@ -9,11 +9,11 @@ import core, {
|
||||
type WorkspaceId,
|
||||
getCollaborativeDocId
|
||||
} from '@hcengineering/core'
|
||||
import { getWorkspaceDB } from '@hcengineering/mongo'
|
||||
import { getMongoClient, getWorkspaceDB } from '@hcengineering/mongo'
|
||||
import { type StorageAdapter } from '@hcengineering/server-core'
|
||||
import { connect } from '@hcengineering/server-tool'
|
||||
import { jsonToText } from '@hcengineering/text'
|
||||
import { type Db, MongoClient } from 'mongodb'
|
||||
import { type Db } from 'mongodb'
|
||||
|
||||
export async function fixJsonMarkup (
|
||||
ctx: MeasureContext,
|
||||
@ -27,8 +27,9 @@ export async function fixJsonMarkup (
|
||||
})) as unknown as CoreClient
|
||||
const hierarchy = connection.getHierarchy()
|
||||
|
||||
const client = new MongoClient(mongoUrl)
|
||||
const db = getWorkspaceDB(client, workspaceId)
|
||||
const client = getMongoClient(mongoUrl)
|
||||
const _client = await client.getClient()
|
||||
const db = getWorkspaceDB(_client, workspaceId)
|
||||
|
||||
try {
|
||||
const classes = hierarchy.getDescendants(core.class.Doc)
|
||||
@ -48,7 +49,7 @@ export async function fixJsonMarkup (
|
||||
await processFixJsonMarkupFor(ctx, domain, _class, filtered, workspaceId, db, storageAdapter)
|
||||
}
|
||||
} finally {
|
||||
await client.close()
|
||||
client.close()
|
||||
await connection.close()
|
||||
}
|
||||
}
|
||||
|
@ -27,9 +27,8 @@ import core, {
|
||||
SortingOrder,
|
||||
type WorkspaceId
|
||||
} from '@hcengineering/core'
|
||||
import { getWorkspaceDB } from '@hcengineering/mongo'
|
||||
import { getMongoClient, getWorkspaceDB } from '@hcengineering/mongo'
|
||||
import { connect } from '@hcengineering/server-tool'
|
||||
import { MongoClient } from 'mongodb'
|
||||
|
||||
interface PropertyInfo {
|
||||
name: string
|
||||
@ -100,10 +99,10 @@ export async function fixMixinForeignAttributes (
|
||||
}
|
||||
|
||||
if (result.size > 0) {
|
||||
const client = new MongoClient(mongoUrl)
|
||||
const client = getMongoClient(mongoUrl)
|
||||
try {
|
||||
await client.connect()
|
||||
const db = getWorkspaceDB(client, workspaceId)
|
||||
const _client = await client.getClient()
|
||||
const db = getWorkspaceDB(_client, workspaceId)
|
||||
|
||||
for (const [mixin, objects] of result) {
|
||||
console.log('fixing', mixin)
|
||||
@ -134,7 +133,7 @@ export async function fixMixinForeignAttributes (
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
await client.close()
|
||||
client.close()
|
||||
}
|
||||
}
|
||||
} catch (err: any) {
|
||||
|
@ -15,13 +15,13 @@
|
||||
//
|
||||
|
||||
import { DOMAIN_TX, type MeasureContext, type Ref, type WorkspaceId } from '@hcengineering/core'
|
||||
import { type StorageAdapter } from '@hcengineering/server-core'
|
||||
import { DOMAIN_ATTACHMENT } from '@hcengineering/model-attachment'
|
||||
import contact, { DOMAIN_CHANNEL } from '@hcengineering/model-contact'
|
||||
import { DOMAIN_TELEGRAM } from '@hcengineering/model-telegram'
|
||||
import { getWorkspaceDB } from '@hcengineering/mongo'
|
||||
import { getMongoClient, getWorkspaceDB } from '@hcengineering/mongo'
|
||||
import { type StorageAdapter } from '@hcengineering/server-core'
|
||||
import telegram, { type SharedTelegramMessage, type SharedTelegramMessages } from '@hcengineering/telegram'
|
||||
import { type Document, MongoClient, type UpdateFilter } from 'mongodb'
|
||||
import { type Document, type UpdateFilter } from 'mongodb'
|
||||
|
||||
const LastMessages = 'last-msgs'
|
||||
|
||||
@ -35,11 +35,11 @@ export async function clearTelegramHistory (
|
||||
tgDb: string,
|
||||
storageAdapter: StorageAdapter
|
||||
): Promise<void> {
|
||||
const client = new MongoClient(mongoUrl)
|
||||
const client = getMongoClient(mongoUrl)
|
||||
try {
|
||||
await client.connect()
|
||||
const workspaceDB = getWorkspaceDB(client, workspaceId)
|
||||
const telegramDB = client.db(tgDb)
|
||||
const _client = await client.getClient()
|
||||
const workspaceDB = getWorkspaceDB(_client, workspaceId)
|
||||
const telegramDB = _client.db(tgDb)
|
||||
|
||||
const sharedMessages = await workspaceDB
|
||||
.collection(DOMAIN_TELEGRAM)
|
||||
@ -99,6 +99,6 @@ export async function clearTelegramHistory (
|
||||
workspace: workspaceId
|
||||
})
|
||||
} finally {
|
||||
await client.close()
|
||||
client.close()
|
||||
}
|
||||
}
|
||||
|
@ -16,25 +16,24 @@
|
||||
|
||||
import contact from '@hcengineering/contact'
|
||||
import core, {
|
||||
type Client as CoreClient,
|
||||
type BackupClient,
|
||||
DOMAIN_TX,
|
||||
type Tx,
|
||||
type WorkspaceId,
|
||||
type Ref,
|
||||
type Client as CoreClient,
|
||||
type Doc,
|
||||
DOMAIN_DOC_INDEX_STATE
|
||||
DOMAIN_DOC_INDEX_STATE,
|
||||
DOMAIN_TX,
|
||||
type Ref,
|
||||
type Tx,
|
||||
type WorkspaceId
|
||||
} from '@hcengineering/core'
|
||||
import { getWorkspaceDB } from '@hcengineering/mongo'
|
||||
import { MongoClient } from 'mongodb'
|
||||
import { generateModelDiff, printDiff } from './mdiff'
|
||||
import { getMongoClient, getWorkspaceDB } from '@hcengineering/mongo'
|
||||
import { connect } from '@hcengineering/server-tool'
|
||||
import { generateModelDiff, printDiff } from './mdiff'
|
||||
|
||||
export async function diffWorkspace (mongoUrl: string, workspace: WorkspaceId, rawTxes: Tx[]): Promise<void> {
|
||||
const client = new MongoClient(mongoUrl)
|
||||
const client = getMongoClient(mongoUrl)
|
||||
try {
|
||||
await client.connect()
|
||||
const db = getWorkspaceDB(client, workspace)
|
||||
const _client = await client.getClient()
|
||||
const db = getWorkspaceDB(_client, workspace)
|
||||
|
||||
console.log('diffing transactions...')
|
||||
|
||||
@ -68,7 +67,7 @@ export async function diffWorkspace (mongoUrl: string, workspace: WorkspaceId, r
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
await client.close()
|
||||
client.close()
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,18 +80,18 @@ export async function updateField (
|
||||
const connection = (await connect(transactorUrl, workspaceId, undefined, {
|
||||
mode: 'backup'
|
||||
})) as unknown as CoreClient & BackupClient
|
||||
const client = new MongoClient(mongoUrl)
|
||||
const client = getMongoClient(mongoUrl)
|
||||
let valueToPut: string | number = cmd.value
|
||||
if (cmd.type === 'number') valueToPut = parseFloat(valueToPut)
|
||||
try {
|
||||
const _client = await client.getClient()
|
||||
try {
|
||||
await client.connect()
|
||||
const db = getWorkspaceDB(client, workspaceId)
|
||||
const db = getWorkspaceDB(_client, workspaceId)
|
||||
await db
|
||||
.collection(cmd.domain)
|
||||
.updateOne({ _id: cmd.objectId as Ref<Doc> }, { $set: { [cmd.attribute]: valueToPut } })
|
||||
} finally {
|
||||
await client.close()
|
||||
client.close()
|
||||
}
|
||||
} finally {
|
||||
await connection.close()
|
||||
@ -104,19 +103,19 @@ export async function recreateElastic (
|
||||
workspaceId: WorkspaceId,
|
||||
transactorUrl: string
|
||||
): Promise<void> {
|
||||
const client = new MongoClient(mongoUrl)
|
||||
const client = getMongoClient(mongoUrl)
|
||||
const _client = await client.getClient()
|
||||
const connection = (await connect(transactorUrl, workspaceId, undefined, {
|
||||
mode: 'backup'
|
||||
})) as unknown as CoreClient & BackupClient
|
||||
try {
|
||||
await client.connect()
|
||||
const db = getWorkspaceDB(client, workspaceId)
|
||||
const db = getWorkspaceDB(_client, workspaceId)
|
||||
await db
|
||||
.collection(DOMAIN_DOC_INDEX_STATE)
|
||||
.updateMany({ _class: core.class.DocIndexState }, { $set: { stages: {} } })
|
||||
await connection.sendForceClose()
|
||||
} finally {
|
||||
await client.close()
|
||||
client.close()
|
||||
await connection.close()
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
"_phase:docker-staging": "rushx docker:staging",
|
||||
"bundle": "mkdir -p bundle && esbuild src/__start.ts --bundle --define:process.env.MODEL_VERSION=$(node ../../common/scripts/show_version.js) --minify --platform=node > bundle/bundle.js",
|
||||
"docker:build": "../../common/scripts/docker_build.sh hardcoreeng/account",
|
||||
"docker:tbuild": "docker build -t hardcoreeng/account . --platform=linux/amd64 && ../../common/scripts/docker_tag_push.sh hardcoreeng/account",
|
||||
"docker:staging": "../../common/scripts/docker_tag.sh hardcoreeng/account staging",
|
||||
"docker:push": "../../common/scripts/docker_tag.sh hardcoreeng/account",
|
||||
"run-local": "cross-env MONGO_URL=mongodb://localhost:27017 MINIO_ACCESS_KEY=minioadmi MINIO_SECRET_KEY=minioadmin MINIO_ENDPOINT=localhost SERVER_SECRET='secret' TRANSACTOR_URL=ws://localhost:3333 ts-node src/__start.ts",
|
||||
|
@ -47,6 +47,7 @@
|
||||
"@hcengineering/platform": "^0.6.11",
|
||||
"@hcengineering/auth-providers": "^0.6.0",
|
||||
"@hcengineering/core": "^0.6.32",
|
||||
"@hcengineering/mongo": "^0.6.1",
|
||||
"mongodb": "^6.8.0",
|
||||
"koa": "^2.15.3",
|
||||
"koa-router": "^12.0.1",
|
||||
|
@ -7,10 +7,10 @@ import account, {
|
||||
EndpointKind,
|
||||
UpgradeWorker,
|
||||
accountId,
|
||||
cleanInProgressWorkspaces,
|
||||
getMethods,
|
||||
cleanExpiredOtp,
|
||||
getAllTransactors
|
||||
cleanInProgressWorkspaces,
|
||||
getAllTransactors,
|
||||
getMethods
|
||||
} from '@hcengineering/account'
|
||||
import accountEn from '@hcengineering/account/lang/en.json'
|
||||
import accountRu from '@hcengineering/account/lang/ru.json'
|
||||
@ -25,6 +25,7 @@ import {
|
||||
type Version
|
||||
} from '@hcengineering/core'
|
||||
import { type MigrateOperation } from '@hcengineering/model'
|
||||
import { getMongoClient, type MongoClientReference } from '@hcengineering/mongo'
|
||||
import platform, { Severity, Status, addStringsLoader, setMetadata } from '@hcengineering/platform'
|
||||
import serverClientPlugin from '@hcengineering/server-client'
|
||||
import serverToken, { decodeToken } from '@hcengineering/server-token'
|
||||
@ -34,7 +35,7 @@ import { type IncomingHttpHeaders } from 'http'
|
||||
import Koa from 'koa'
|
||||
import bodyParser from 'koa-bodyparser'
|
||||
import Router from 'koa-router'
|
||||
import { MongoClient } from 'mongodb'
|
||||
import type { MongoClient } from 'mongodb'
|
||||
import os from 'os'
|
||||
|
||||
/**
|
||||
@ -106,7 +107,8 @@ export function serveAccount (
|
||||
}
|
||||
setMetadata(serverClientPlugin.metadata.UserAgent, 'AccountService')
|
||||
|
||||
let client: MongoClient | Promise<MongoClient> = MongoClient.connect(dbUri)
|
||||
const client: MongoClientReference = getMongoClient(dbUri)
|
||||
let _client: MongoClient | Promise<MongoClient> = client.getClient()
|
||||
|
||||
let worker: UpgradeWorker | undefined
|
||||
|
||||
@ -120,7 +122,7 @@ export function serveAccount (
|
||||
)
|
||||
app.use(bodyParser())
|
||||
|
||||
void client.then(async (p: MongoClient) => {
|
||||
void client.getClient().then(async (p: MongoClient) => {
|
||||
const db = p.db(ACCOUNT_DB)
|
||||
registerProviders(measureCtx, app, router, db, productId, serverSecret, frontURL, brandings)
|
||||
|
||||
@ -237,10 +239,10 @@ export function serveAccount (
|
||||
ctx.body = JSON.stringify(response)
|
||||
}
|
||||
|
||||
if (client instanceof Promise) {
|
||||
client = await client
|
||||
if (_client instanceof Promise) {
|
||||
_client = await _client
|
||||
}
|
||||
const db = client.db(ACCOUNT_DB)
|
||||
const db = _client.db(ACCOUNT_DB)
|
||||
|
||||
let host: string | undefined
|
||||
const origin = ctx.request.headers.origin ?? ctx.request.headers.referer
|
||||
@ -269,7 +271,7 @@ export function serveAccount (
|
||||
if (client instanceof Promise) {
|
||||
void client.then((c) => c.close())
|
||||
} else {
|
||||
void client.close()
|
||||
client.close()
|
||||
}
|
||||
server.close()
|
||||
}
|
||||
|
@ -258,7 +258,6 @@ export async function upgradeModel (
|
||||
throw Error('Model txes must target only core.space.Model')
|
||||
}
|
||||
|
||||
// const client = new MongoClient(mongodbUri)
|
||||
const _client = getMongoClient(mongodbUri)
|
||||
const client = await _client.getClient()
|
||||
const storageConfig: StorageConfiguration = storageConfigFromEnv()
|
||||
|
@ -61,6 +61,7 @@
|
||||
"@hcengineering/contact": "^0.6.24",
|
||||
"@hcengineering/core": "^0.6.32",
|
||||
"@hcengineering/platform": "^0.6.11",
|
||||
"@hcengineering/mongo": "^0.6.1",
|
||||
"@hcengineering/setting": "^0.6.17",
|
||||
"@hcengineering/text": "^0.6.5",
|
||||
"@hcengineering/server-client": "^0.6.0",
|
||||
|
@ -13,16 +13,17 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import { MongoClientReference, getMongoClient } from '@hcengineering/mongo'
|
||||
import { MongoClient } from 'mongodb'
|
||||
|
||||
import config from './config'
|
||||
|
||||
const clientRef: MongoClientReference = getMongoClient(config.MongoURI)
|
||||
let client: MongoClient | undefined
|
||||
export const getDB = (() => {
|
||||
return async () => {
|
||||
if (client === undefined) {
|
||||
client = new MongoClient(config.MongoURI)
|
||||
await client.connect()
|
||||
client = await clientRef.getClient()
|
||||
}
|
||||
|
||||
return client.db(config.MongoDB)
|
||||
@ -30,7 +31,5 @@ export const getDB = (() => {
|
||||
})()
|
||||
|
||||
export const closeDB: () => Promise<void> = async () => {
|
||||
if (client !== undefined) {
|
||||
await client.close()
|
||||
}
|
||||
clientRef.close()
|
||||
}
|
||||
|
@ -58,6 +58,7 @@
|
||||
"@hcengineering/client": "^0.6.18",
|
||||
"@hcengineering/client-resources": "^0.6.27",
|
||||
"@hcengineering/contact": "^0.6.24",
|
||||
"@hcengineering/mongo": "^0.6.1",
|
||||
"@hcengineering/core": "^0.6.32",
|
||||
"@hcengineering/gmail": "^0.6.22",
|
||||
"@hcengineering/server-token": "^0.6.11",
|
||||
|
@ -14,16 +14,17 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import { MongoClientReference, getMongoClient } from '@hcengineering/mongo'
|
||||
import { MongoClient } from 'mongodb'
|
||||
|
||||
import config from './config'
|
||||
|
||||
const clientRef: MongoClientReference = getMongoClient(config.MongoURI)
|
||||
let client: MongoClient | undefined
|
||||
export const getDB = (() => {
|
||||
return async () => {
|
||||
if (client === undefined) {
|
||||
client = new MongoClient(config.MongoURI)
|
||||
await client.connect()
|
||||
client = await clientRef.getClient()
|
||||
}
|
||||
|
||||
return client.db(config.MongoDB)
|
||||
@ -31,7 +32,5 @@ export const getDB = (() => {
|
||||
})()
|
||||
|
||||
export const closeDB: () => Promise<void> = async () => {
|
||||
if (client !== undefined) {
|
||||
await client.close()
|
||||
}
|
||||
clientRef.close()
|
||||
}
|
||||
|
@ -66,6 +66,7 @@
|
||||
"@hcengineering/telegram": "^0.6.21",
|
||||
"@hcengineering/server-token": "^0.6.11",
|
||||
"@hcengineering/server-client": "^0.6.0",
|
||||
"@hcengineering/mongo": "^0.6.1",
|
||||
"big-integer": "^1.6.51",
|
||||
"dotenv": "~16.0.0",
|
||||
"cors": "^2.8.5",
|
||||
|
@ -1,16 +1,20 @@
|
||||
import { MongoClientReference, getMongoClient } from '@hcengineering/mongo'
|
||||
import { MongoClient } from 'mongodb'
|
||||
|
||||
import config from './config'
|
||||
|
||||
const clientRef: MongoClientReference = getMongoClient(config.MongoURI)
|
||||
let client: MongoClient | undefined
|
||||
export const getDB = (() => {
|
||||
let client: MongoClient | undefined
|
||||
|
||||
return async () => {
|
||||
if (client === undefined) {
|
||||
client = new MongoClient(config.MongoURI)
|
||||
await client.connect()
|
||||
client = await clientRef.getClient()
|
||||
}
|
||||
|
||||
return client.db(config.MongoDB)
|
||||
}
|
||||
})()
|
||||
|
||||
export const closeDB: () => Promise<void> = async () => {
|
||||
clientRef.close()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user