Skip to content

Commit

Permalink
Checks state on global db var
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego committed Apr 27, 2022
1 parent a61bb91 commit d9fd955
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions apps/meteor/ee/server/services/mongo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ function connectDb(poolSize: number): Promise<MongoClient> {
});
}

let db: Db;

export const getConnection = ((): ((poolSize?: number) => Promise<Db>) => {
let db: Db;
let client: Promise<MongoClient>;

return async (poolSize = 5): Promise<Db> => {
Expand All @@ -49,6 +50,8 @@ export const getConnection = ((): ((poolSize?: number) => Promise<Db>) => {
})();

export async function getCollection<T>(name: Collections): Promise<Collection<T>> {
const db = await getConnection();
if (!db) {
db = await getConnection();
}
return db.collection<T>(name);
}

0 comments on commit d9fd955

Please sign in to comment.