gcf-common-lib 0.29.62 → 0.30.62

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gcf-common-lib",
3
3
  "description": "",
4
- "version": "0.29.62",
4
+ "version": "0.30.62",
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "branches": [
@@ -30,7 +30,7 @@
30
30
  "bluebird": "^3.7.2",
31
31
  "lodash": "^4.17.21",
32
32
  "moment": "^2.30.1",
33
- "mongodb": "^4.17.2",
33
+ "mongodb": "^6.5.0",
34
34
  "rxjs": "^7.8.1"
35
35
  },
36
36
  "devDependencies": {
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.MongoHelper = void 0;
7
7
  const mongodb_1 = require("mongodb");
8
8
  const bluebird_1 = __importDefault(require("bluebird"));
9
+ let mongoClient;
9
10
  exports.MongoHelper = {
10
11
  async collectionExists(client, name) {
11
12
  const db = client.db();
@@ -27,8 +28,14 @@ exports.MongoHelper = {
27
28
  async withMongoClient(fn, url, mongoClientOptions) {
28
29
  function withDisposer() {
29
30
  return bluebird_1.default.method(async () => {
30
- return new mongodb_1.MongoClient(url, mongoClientOptions).connect();
31
- })().disposer((client, promise) => client.close());
31
+ if (!mongoClient) {
32
+ mongoClient = new mongodb_1.MongoClient(url, mongoClientOptions);
33
+ await mongoClient.connect();
34
+ }
35
+ return mongoClient;
36
+ })().disposer((client, promise) => {
37
+ // client.close();
38
+ });
32
39
  }
33
40
  return bluebird_1.default.using(withDisposer(), client => fn(client));
34
41
  },
@@ -1,6 +1,7 @@
1
1
  import { Collection, CreateCollectionOptions, MongoClient, MongoClientOptions } from 'mongodb';
2
2
  import { Document } from 'bson';
3
3
  import Bluebird from 'bluebird';
4
+ let mongoClient: MongoClient;
4
5
 
5
6
  export const MongoHelper = {
6
7
  async collectionExists(client: MongoClient, name: string) {
@@ -35,8 +36,14 @@ export const MongoHelper = {
35
36
  ) {
36
37
  function withDisposer() {
37
38
  return Bluebird.method(async () => {
38
- return new MongoClient(url, mongoClientOptions).connect();
39
- })().disposer((client, promise) => client.close());
39
+ if (!mongoClient) {
40
+ mongoClient = new MongoClient(url, mongoClientOptions);
41
+ await mongoClient.connect();
42
+ }
43
+ return mongoClient;
44
+ })().disposer((client, promise) => {
45
+ // client.close();
46
+ });
40
47
  }
41
48
 
42
49
  return Bluebird.using(withDisposer(), client => fn(client));